bun run format

This commit is contained in:
2026-01-27 19:43:32 -03:00
parent 37f1b46306
commit e1864660a7
19 changed files with 115 additions and 121 deletions

View File

@@ -1,4 +1,5 @@
# Package Managers # Package Managers
src/lib/components/ui/
package-lock.json package-lock.json
pnpm-lock.yaml pnpm-lock.yaml
yarn.lock yarn.lock

View File

@@ -1,12 +1,9 @@
{ {
"useTabs": true, "useTabs": true,
"singleQuote": true, "singleQuote": false,
"trailingComma": "none", "trailingComma": "none",
"printWidth": 100, "printWidth": 100,
"plugins": [ "plugins": ["prettier-plugin-svelte", "prettier-plugin-tailwindcss"],
"prettier-plugin-svelte",
"prettier-plugin-tailwindcss"
],
"overrides": [ "overrides": [
{ {
"files": "*.svelte", "files": "*.svelte",

View File

@@ -16,7 +16,10 @@
let { let {
post, post,
variant = 'icon-lg' variant = 'icon-lg'
}: { post: Omit<Partial<Post>, 'authorId'> & { authorId: string; id: string }; variant?: 'icon-lg' | 'default' | 'sm' | 'lg' | 'icon' | 'icon-sm' } = $props(); }: {
post: Omit<Partial<Post>, 'authorId'> & { authorId: string; id: string };
variant?: 'icon-lg' | 'default' | 'sm' | 'lg' | 'icon' | 'icon-sm';
} = $props();
let seguido: boolean | null = $state(null); let seguido: boolean | null = $state(null);

View File

@@ -1,16 +1,16 @@
import { apiBase } from "@/stores/url"; import { apiBase } from '@/stores/url';
import { get } from "svelte/store"; import { get } from 'svelte/store';
export async function checkEmail(email: string) { export async function checkEmail(email: string) {
try { try {
const req = await fetch(`${get(apiBase)}/api/users/check-email/${email}`, { const req = await fetch(`${get(apiBase)}/api/users/check-email/${email}`, {
method: "GET" method: 'GET'
}); });
if (req.ok){ if (req.ok) {
return (await req.json()).available; return (await req.json()).available;
} }
return false; return false;
} catch { } catch {
return false; return false;
} }
} }

View File

@@ -1,16 +1,16 @@
import { apiBase } from "@/stores/url"; import { apiBase } from '@/stores/url';
import { get } from "svelte/store"; import { get } from 'svelte/store';
export async function checkUsername(username: string) { export async function checkUsername(username: string) {
try { try {
const req = await fetch(`${get(apiBase)}/api/users/check-username/${username}`, { const req = await fetch(`${get(apiBase)}/api/users/check-username/${username}`, {
method: "GET" method: 'GET'
}); });
if (req.ok){ if (req.ok) {
return (await req.json()).available; return (await req.json()).available;
} }
return false; return false;
} catch { } catch {
return false; return false;
} }
} }

View File

@@ -1,6 +1,6 @@
import { apiBase } from "@/stores/url"; import { apiBase } from '@/stores/url';
import { sesionStore } from "@/stores/usuario"; import { sesionStore } from '@/stores/usuario';
import { get } from "svelte/store"; import { get } from 'svelte/store';
import type { Post } from '../../types'; import type { Post } from '../../types';
import { PAGE_SIZE } from '../stores/posts'; import { PAGE_SIZE } from '../stores/posts';
@@ -10,12 +10,11 @@ export async function getPosts(page: number = 1): Promise<Post[]> {
const headers: HeadersInit = {}; const headers: HeadersInit = {};
if (token) headers.Authorization = `Bearer ${token}`; if (token) headers.Authorization = `Bearer ${token}`;
const res = await fetch( const res = await fetch(`${get(apiBase)}/timeline?page=${page}&pageSize=${PAGE_SIZE}`, {
`${get(apiBase)}/timeline?page=${page}&pageSize=${PAGE_SIZE}`, headers
{ headers } });
);
if (!res.ok) throw new Error('Error cargando posts'); if (!res.ok) throw new Error('Error cargando posts');
return res.json(); return res.json();
} }

View File

@@ -4,7 +4,7 @@ import { sesionStore } from '@/stores/usuario';
import type { Post } from '../../types'; import type { Post } from '../../types';
export async function likePost(post: Post) { export async function likePost(post: Post) {
let method = post.isLiked ? "DELETE" : "POST"; let method = post.isLiked ? 'DELETE' : 'POST';
try { try {
const req = await fetch(get(apiBase) + `/api/posts/${post.id}/like`, { const req = await fetch(get(apiBase) + `/api/posts/${post.id}/like`, {
method: method, method: method,

View File

@@ -24,7 +24,7 @@ export async function loadMorePosts() {
if (newPosts.length < PAGE_SIZE) { if (newPosts.length < PAGE_SIZE) {
finished = true; finished = true;
} else { } else {
page.update(p => p + 1); page.update((p) => p + 1);
} }
} finally { } finally {
loadingPosts.set(false); loadingPosts.set(false);

View File

@@ -13,13 +13,16 @@ export async function obtenerSeguidoresPorUsuario(
const fetchFunc = fetch2 || fetch; const fetchFunc = fetch2 || fetch;
const skip = (page - 1) * limit; const skip = (page - 1) * limit;
const response = await fetchFunc(`${get(apiBase)}/api/users/${id}/followers?skip=${skip}&limit=${limit}`, { const response = await fetchFunc(
method: 'GET', `${get(apiBase)}/api/users/${id}/followers?skip=${skip}&limit=${limit}`,
headers: { {
'Content-Type': 'application/json', method: 'GET',
Authorization: `Bearer ${get(sesionStore)?.accessToken}` headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${get(sesionStore)?.accessToken}`
}
} }
}); );
if (!response.ok) { if (!response.ok) {
return null; return null;
@@ -30,4 +33,4 @@ export async function obtenerSeguidoresPorUsuario(
} catch (error) { } catch (error) {
return null; return null;
} }
} }

View File

@@ -13,13 +13,16 @@ export async function obtenerSeguidosPorUsuario(
const fetchFunc = fetch2 || fetch; const fetchFunc = fetch2 || fetch;
const skip = (page - 1) * limit; const skip = (page - 1) * limit;
const response = await fetchFunc(`${get(apiBase)}/api/users/${id}/following?skip=${skip}&limit=${limit}`, { const response = await fetchFunc(
method: 'GET', `${get(apiBase)}/api/users/${id}/following?skip=${skip}&limit=${limit}`,
headers: { {
'Content-Type': 'application/json', method: 'GET',
Authorization: `Bearer ${get(sesionStore)?.accessToken}` headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${get(sesionStore)?.accessToken}`
}
} }
}); );
if (!response.ok) { if (!response.ok) {
return null; return null;
@@ -30,4 +33,4 @@ export async function obtenerSeguidosPorUsuario(
} catch (error) { } catch (error) {
return null; return null;
} }
} }

View File

@@ -1,27 +1,27 @@
import { addPost } from "@/stores/posts"; import { addPost } from '@/stores/posts';
import { apiBase } from "@/stores/url"; import { apiBase } from '@/stores/url';
import { sesionStore } from "@/stores/usuario"; import { sesionStore } from '@/stores/usuario';
import { get } from "svelte/store"; import { get } from 'svelte/store';
export async function publicarPost(formData: FormData){ export async function publicarPost(formData: FormData) {
try{ try {
const req = fetch(get(apiBase) + '/api/posts', { const req = fetch(get(apiBase) + '/api/posts', {
method: 'POST', method: 'POST',
//credentials: 'include', //credentials: 'include',
headers: { headers: {
Authorization: `Bearer ${get(sesionStore)?.accessToken}` Authorization: `Bearer ${get(sesionStore)?.accessToken}`
}, },
body: formData body: formData
}); });
const res = await req; const res = await req;
if (res.ok) { if (res.ok) {
const post = await res.json(); const post = await res.json();
addPost(post); addPost(post);
return ''; return '';
}
return 'No se pudo crear el post.';
} catch {
return 'Fallo al alcanzar el servidor';
} }
return 'No se pudo crear el post.';
} catch {
return 'Fallo al alcanzar el servidor';
}
} }

View File

@@ -1,7 +1,4 @@
export async function updateImagenDePerfil(){ export async function updateImagenDePerfil() {
try{ try {
} catch {}
}catch{
}
} }

View File

@@ -5,9 +5,9 @@ import { sesionStore } from '@/stores/usuario';
export async function updatePost(post: Post, callbackfn: Function, message: string) { export async function updatePost(post: Post, callbackfn: Function, message: string) {
try { try {
const formData = new FormData(); const formData = new FormData();
formData.append("content", post.content); formData.append('content', post.content);
formData.append("image", post.image||""); formData.append('image', post.image || '');
const req = await fetch(get(apiBase) + `/api/posts/${post.id}`, { const req = await fetch(get(apiBase) + `/api/posts/${post.id}`, {
method: 'PUT', method: 'PUT',

View File

@@ -19,21 +19,14 @@ export const addPost = (post: Post) => {
posts.update((current) => [post, ...current]); posts.update((current) => [post, ...current]);
}; };
export const updatePostStore = ( export const updatePostStore = (postId: string, updatedData: Partial<Post>) => {
postId: string,
updatedData: Partial<Post>
) => {
posts.update((current) => posts.update((current) =>
current.map((post) => current.map((post) => (post.id === postId ? { ...post, ...updatedData } : post))
post.id === postId ? { ...post, ...updatedData } : post
)
); );
}; };
export const removePost = (postId: string) => { export const removePost = (postId: string) => {
posts.update((current) => posts.update((current) => current.filter((post) => post.id !== postId));
current.filter((post) => post.id !== postId)
);
}; };
export const resetPosts = () => { export const resetPosts = () => {

View File

@@ -13,11 +13,11 @@ export type WithoutChildrenOrChild<T> = WithoutChildren<WithoutChild<T>>;
export type WithElementRef<T, U extends HTMLElement = HTMLElement> = T & { ref?: U | null }; export type WithElementRef<T, U extends HTMLElement = HTMLElement> = T & { ref?: U | null };
export function filtrarImagen(file: File) { export function filtrarImagen(file: File) {
if (file) { if (file) {
const allowed = ['image/png', 'image/jpg', 'image/jpeg', 'image/gif', 'image/webp']; const allowed = ['image/png', 'image/jpg', 'image/jpeg', 'image/gif', 'image/webp'];
if (allowed.includes(file.type)) { if (allowed.includes(file.type)) {
return file; return file;
} }
} }
return null; return null;
} }

View File

@@ -1,5 +1,5 @@
import { obtenerUsuarioPorUsername } from '@/hooks/obtenerUsuario.js'; import { obtenerUsuarioPorUsername } from '@/hooks/obtenerUsuario.js';
import type {UserResponseDto } from '../../types.js'; import type { UserResponseDto } from '../../types.js';
import { error } from '@sveltejs/kit'; import { error } from '@sveltejs/kit';
import type { PageLoad } from './$types'; import type { PageLoad } from './$types';
import { obtenerSeguidosPorUsuario } from '@/hooks/obtenerSeguidosPorUsuario.js'; import { obtenerSeguidosPorUsuario } from '@/hooks/obtenerSeguidosPorUsuario.js';
@@ -26,4 +26,4 @@ export const load: PageLoad = async ({ params, depends, fetch }) => {
countSeguidores: countSeguidores.count, countSeguidores: countSeguidores.count,
countSeguidos: countSeguidos.count countSeguidos: countSeguidos.count
}; };
}; };

View File

@@ -14,7 +14,7 @@
}; };
let { data }: { data: Data } = $props(); let { data }: { data: Data } = $props();
let currentPage = $state(1); let currentPage = $state(1);
let isLoading = $state(false); let isLoading = $state(false);
const limit = 100; const limit = 100;
@@ -23,19 +23,18 @@
async function loadPage(page: number) { async function loadPage(page: number) {
if (isLoading) return; if (isLoading) return;
isLoading = true; isLoading = true;
const response = await obtenerSeguidoresPorUsuario(data.usuario.id, page, limit); const response = await obtenerSeguidoresPorUsuario(data.usuario.id, page, limit);
if (response) { if (response) {
data.seguidores = response.response as UserResponseDto[]; data.seguidores = response.response as UserResponseDto[];
data.totalCount = response.totalCount; data.totalCount = response.totalCount;
currentPage = page; currentPage = page;
} }
isLoading = false; isLoading = false;
} }
</script> </script>
<div class="flex min-h-fit w-full items-center justify-center p-6 md:p-10"> <div class="flex min-h-fit w-full items-center justify-center p-6 md:p-10">
@@ -51,7 +50,7 @@
<ArrowLeft /> <ArrowLeft />
</button> </button>
</div> </div>
{#if isLoading} {#if isLoading}
<div class="py-8 text-center text-muted-foreground"> <div class="py-8 text-center text-muted-foreground">
<p>Cargando...</p> <p>Cargando...</p>
@@ -79,11 +78,11 @@
> >
<ChevronLeft class="h-5 w-5" /> <ChevronLeft class="h-5 w-5" />
</button> </button>
<span class="px-4 text-sm text-muted-foreground"> <span class="px-4 text-sm text-muted-foreground">
Página {currentPage} de {totalPages} Página {currentPage} de {totalPages}
</span> </span>
<button <button
class="rounded-md border bg-card p-2 hover:bg-accent disabled:cursor-not-allowed disabled:opacity-50" class="rounded-md border bg-card p-2 hover:bg-accent disabled:cursor-not-allowed disabled:opacity-50"
onclick={() => loadPage(currentPage + 1)} onclick={() => loadPage(currentPage + 1)}
@@ -94,4 +93,4 @@
</div> </div>
{/if} {/if}
</div> </div>
</div> </div>

View File

@@ -19,4 +19,4 @@ export const load: PageLoad = async ({ params, fetch }) => {
usuario, usuario,
seguidores: seguidoresResponse?.response || [] seguidores: seguidoresResponse?.response || []
}; };
} };

View File

@@ -14,7 +14,7 @@
}; };
let { data }: { data: Data } = $props(); let { data }: { data: Data } = $props();
let currentPage = $state(1); let currentPage = $state(1);
let isLoading = $state(false); let isLoading = $state(false);
const limit = 100; const limit = 100;
@@ -23,19 +23,18 @@
async function loadPage(page: number) { async function loadPage(page: number) {
if (isLoading) return; if (isLoading) return;
isLoading = true; isLoading = true;
const response = await obtenerSeguidosPorUsuario(data.usuario.id, page, limit); const response = await obtenerSeguidosPorUsuario(data.usuario.id, page, limit);
if (response) { if (response) {
data.seguidos = response.response as UserResponseDto[]; data.seguidos = response.response as UserResponseDto[];
data.totalCount = response.totalCount; data.totalCount = response.totalCount;
currentPage = page; currentPage = page;
} }
isLoading = false; isLoading = false;
} }
</script> </script>
<div class="flex min-h-fit w-full items-center justify-center p-6 md:p-10"> <div class="flex min-h-fit w-full items-center justify-center p-6 md:p-10">
@@ -51,7 +50,7 @@
<ArrowLeft /> <ArrowLeft />
</button> </button>
</div> </div>
{#if isLoading} {#if isLoading}
<div class="py-8 text-center text-muted-foreground"> <div class="py-8 text-center text-muted-foreground">
<p>Cargando...</p> <p>Cargando...</p>
@@ -79,11 +78,11 @@
> >
<ChevronLeft class="h-5 w-5" /> <ChevronLeft class="h-5 w-5" />
</button> </button>
<span class="px-4 text-sm text-muted-foreground"> <span class="px-4 text-sm text-muted-foreground">
Página {currentPage} de {totalPages} Página {currentPage} de {totalPages}
</span> </span>
<button <button
class="rounded-md border bg-card p-2 hover:bg-accent disabled:cursor-not-allowed disabled:opacity-50" class="rounded-md border bg-card p-2 hover:bg-accent disabled:cursor-not-allowed disabled:opacity-50"
onclick={() => loadPage(currentPage + 1)} onclick={() => loadPage(currentPage + 1)}
@@ -94,4 +93,4 @@
</div> </div>
{/if} {/if}
</div> </div>
</div> </div>