From e1864660a786cd54ff8059002cbab959b5aa05d6 Mon Sep 17 00:00:00 2001 From: fede Date: Tue, 27 Jan 2026 19:43:32 -0300 Subject: [PATCH] bun run format --- .prettierignore | 1 + .prettierrc | 7 +-- src/lib/components/BotonSeguir.svelte | 5 ++- src/lib/hooks/checkEmail.ts | 26 +++++------ src/lib/hooks/checkUsername.ts | 26 +++++------ src/lib/hooks/getPosts.ts | 15 +++---- src/lib/hooks/likePost.ts | 2 +- src/lib/hooks/loadMorePosts.ts | 2 +- src/lib/hooks/obtenerSeguidoresPorUsuario.ts | 17 +++++--- src/lib/hooks/obtenerSeguidosPorUsuario.ts | 17 +++++--- src/lib/hooks/publicarPost.ts | 46 ++++++++++---------- src/lib/hooks/updateImagenDePerfil.ts | 9 ++-- src/lib/hooks/updatePost.ts | 6 +-- src/lib/stores/posts.ts | 13 ++---- src/lib/utils.ts | 4 +- src/routes/[perfil]/+page.ts | 4 +- src/routes/[perfil]/seguidores/+page.svelte | 17 ++++---- src/routes/[perfil]/seguidores/+page.ts | 2 +- src/routes/[perfil]/seguidos/+page.svelte | 17 ++++---- 19 files changed, 115 insertions(+), 121 deletions(-) diff --git a/.prettierignore b/.prettierignore index 7d74fe2..4e78dfa 100644 --- a/.prettierignore +++ b/.prettierignore @@ -1,4 +1,5 @@ # Package Managers +src/lib/components/ui/ package-lock.json pnpm-lock.yaml yarn.lock diff --git a/.prettierrc b/.prettierrc index 8855237..eb4a7ba 100644 --- a/.prettierrc +++ b/.prettierrc @@ -1,12 +1,9 @@ { "useTabs": true, - "singleQuote": true, + "singleQuote": false, "trailingComma": "none", "printWidth": 100, - "plugins": [ - "prettier-plugin-svelte", - "prettier-plugin-tailwindcss" - ], + "plugins": ["prettier-plugin-svelte", "prettier-plugin-tailwindcss"], "overrides": [ { "files": "*.svelte", diff --git a/src/lib/components/BotonSeguir.svelte b/src/lib/components/BotonSeguir.svelte index e64aab3..2a083b3 100644 --- a/src/lib/components/BotonSeguir.svelte +++ b/src/lib/components/BotonSeguir.svelte @@ -16,7 +16,10 @@ let { post, variant = 'icon-lg' - }: { post: Omit, 'authorId'> & { authorId: string; id: string }; variant?: 'icon-lg' | 'default' | 'sm' | 'lg' | 'icon' | 'icon-sm' } = $props(); + }: { + post: Omit, 'authorId'> & { authorId: string; id: string }; + variant?: 'icon-lg' | 'default' | 'sm' | 'lg' | 'icon' | 'icon-sm'; + } = $props(); let seguido: boolean | null = $state(null); diff --git a/src/lib/hooks/checkEmail.ts b/src/lib/hooks/checkEmail.ts index 2bbc8e8..5d3176c 100644 --- a/src/lib/hooks/checkEmail.ts +++ b/src/lib/hooks/checkEmail.ts @@ -1,16 +1,16 @@ -import { apiBase } from "@/stores/url"; -import { get } from "svelte/store"; +import { apiBase } from '@/stores/url'; +import { get } from 'svelte/store'; export async function checkEmail(email: string) { - try { - const req = await fetch(`${get(apiBase)}/api/users/check-email/${email}`, { - method: "GET" - }); - if (req.ok){ - return (await req.json()).available; - } - return false; - } catch { - return false; - } + try { + const req = await fetch(`${get(apiBase)}/api/users/check-email/${email}`, { + method: 'GET' + }); + if (req.ok) { + return (await req.json()).available; + } + return false; + } catch { + return false; + } } diff --git a/src/lib/hooks/checkUsername.ts b/src/lib/hooks/checkUsername.ts index 2d82818..c950b5e 100644 --- a/src/lib/hooks/checkUsername.ts +++ b/src/lib/hooks/checkUsername.ts @@ -1,16 +1,16 @@ -import { apiBase } from "@/stores/url"; -import { get } from "svelte/store"; +import { apiBase } from '@/stores/url'; +import { get } from 'svelte/store'; export async function checkUsername(username: string) { - try { - const req = await fetch(`${get(apiBase)}/api/users/check-username/${username}`, { - method: "GET" - }); - if (req.ok){ - return (await req.json()).available; - } - return false; - } catch { - return false; - } + try { + const req = await fetch(`${get(apiBase)}/api/users/check-username/${username}`, { + method: 'GET' + }); + if (req.ok) { + return (await req.json()).available; + } + return false; + } catch { + return false; + } } diff --git a/src/lib/hooks/getPosts.ts b/src/lib/hooks/getPosts.ts index 040b95b..d40111d 100644 --- a/src/lib/hooks/getPosts.ts +++ b/src/lib/hooks/getPosts.ts @@ -1,6 +1,6 @@ -import { apiBase } from "@/stores/url"; -import { sesionStore } from "@/stores/usuario"; -import { get } from "svelte/store"; +import { apiBase } from '@/stores/url'; +import { sesionStore } from '@/stores/usuario'; +import { get } from 'svelte/store'; import type { Post } from '../../types'; import { PAGE_SIZE } from '../stores/posts'; @@ -10,12 +10,11 @@ export async function getPosts(page: number = 1): Promise { const headers: HeadersInit = {}; if (token) headers.Authorization = `Bearer ${token}`; - const res = await fetch( - `${get(apiBase)}/timeline?page=${page}&pageSize=${PAGE_SIZE}`, - { headers } - ); + const res = await fetch(`${get(apiBase)}/timeline?page=${page}&pageSize=${PAGE_SIZE}`, { + headers + }); if (!res.ok) throw new Error('Error cargando posts'); return res.json(); -} \ No newline at end of file +} diff --git a/src/lib/hooks/likePost.ts b/src/lib/hooks/likePost.ts index a16787c..691acae 100644 --- a/src/lib/hooks/likePost.ts +++ b/src/lib/hooks/likePost.ts @@ -4,7 +4,7 @@ import { sesionStore } from '@/stores/usuario'; import type { Post } from '../../types'; export async function likePost(post: Post) { - let method = post.isLiked ? "DELETE" : "POST"; + let method = post.isLiked ? 'DELETE' : 'POST'; try { const req = await fetch(get(apiBase) + `/api/posts/${post.id}/like`, { method: method, diff --git a/src/lib/hooks/loadMorePosts.ts b/src/lib/hooks/loadMorePosts.ts index e126152..8a89428 100644 --- a/src/lib/hooks/loadMorePosts.ts +++ b/src/lib/hooks/loadMorePosts.ts @@ -24,7 +24,7 @@ export async function loadMorePosts() { if (newPosts.length < PAGE_SIZE) { finished = true; } else { - page.update(p => p + 1); + page.update((p) => p + 1); } } finally { loadingPosts.set(false); diff --git a/src/lib/hooks/obtenerSeguidoresPorUsuario.ts b/src/lib/hooks/obtenerSeguidoresPorUsuario.ts index 4f576da..a8fe627 100644 --- a/src/lib/hooks/obtenerSeguidoresPorUsuario.ts +++ b/src/lib/hooks/obtenerSeguidoresPorUsuario.ts @@ -13,13 +13,16 @@ export async function obtenerSeguidoresPorUsuario( const fetchFunc = fetch2 || fetch; const skip = (page - 1) * limit; - const response = await fetchFunc(`${get(apiBase)}/api/users/${id}/followers?skip=${skip}&limit=${limit}`, { - method: 'GET', - headers: { - 'Content-Type': 'application/json', - Authorization: `Bearer ${get(sesionStore)?.accessToken}` + const response = await fetchFunc( + `${get(apiBase)}/api/users/${id}/followers?skip=${skip}&limit=${limit}`, + { + method: 'GET', + headers: { + 'Content-Type': 'application/json', + Authorization: `Bearer ${get(sesionStore)?.accessToken}` + } } - }); + ); if (!response.ok) { return null; @@ -30,4 +33,4 @@ export async function obtenerSeguidoresPorUsuario( } catch (error) { return null; } -} \ No newline at end of file +} diff --git a/src/lib/hooks/obtenerSeguidosPorUsuario.ts b/src/lib/hooks/obtenerSeguidosPorUsuario.ts index b8fc1c8..0bc91cb 100644 --- a/src/lib/hooks/obtenerSeguidosPorUsuario.ts +++ b/src/lib/hooks/obtenerSeguidosPorUsuario.ts @@ -13,13 +13,16 @@ export async function obtenerSeguidosPorUsuario( const fetchFunc = fetch2 || fetch; const skip = (page - 1) * limit; - const response = await fetchFunc(`${get(apiBase)}/api/users/${id}/following?skip=${skip}&limit=${limit}`, { - method: 'GET', - headers: { - 'Content-Type': 'application/json', - Authorization: `Bearer ${get(sesionStore)?.accessToken}` + const response = await fetchFunc( + `${get(apiBase)}/api/users/${id}/following?skip=${skip}&limit=${limit}`, + { + method: 'GET', + headers: { + 'Content-Type': 'application/json', + Authorization: `Bearer ${get(sesionStore)?.accessToken}` + } } - }); + ); if (!response.ok) { return null; @@ -30,4 +33,4 @@ export async function obtenerSeguidosPorUsuario( } catch (error) { return null; } -} \ No newline at end of file +} diff --git a/src/lib/hooks/publicarPost.ts b/src/lib/hooks/publicarPost.ts index 8ddb6f0..e32b3c5 100644 --- a/src/lib/hooks/publicarPost.ts +++ b/src/lib/hooks/publicarPost.ts @@ -1,27 +1,27 @@ -import { addPost } from "@/stores/posts"; -import { apiBase } from "@/stores/url"; -import { sesionStore } from "@/stores/usuario"; -import { get } from "svelte/store"; +import { addPost } from '@/stores/posts'; +import { apiBase } from '@/stores/url'; +import { sesionStore } from '@/stores/usuario'; +import { get } from 'svelte/store'; -export async function publicarPost(formData: FormData){ - try{ - const req = fetch(get(apiBase) + '/api/posts', { - method: 'POST', - //credentials: 'include', - headers: { - Authorization: `Bearer ${get(sesionStore)?.accessToken}` - }, - body: formData - }); +export async function publicarPost(formData: FormData) { + try { + const req = fetch(get(apiBase) + '/api/posts', { + method: 'POST', + //credentials: 'include', + headers: { + Authorization: `Bearer ${get(sesionStore)?.accessToken}` + }, + body: formData + }); - const res = await req; - if (res.ok) { - const post = await res.json(); - addPost(post); - return ''; - } - return 'No se pudo crear el post.'; - } catch { - return 'Fallo al alcanzar el servidor'; + const res = await req; + if (res.ok) { + const post = await res.json(); + addPost(post); + return ''; } + return 'No se pudo crear el post.'; + } catch { + return 'Fallo al alcanzar el servidor'; + } } diff --git a/src/lib/hooks/updateImagenDePerfil.ts b/src/lib/hooks/updateImagenDePerfil.ts index 6b28196..e0e0d54 100644 --- a/src/lib/hooks/updateImagenDePerfil.ts +++ b/src/lib/hooks/updateImagenDePerfil.ts @@ -1,7 +1,4 @@ -export async function updateImagenDePerfil(){ - try{ - - }catch{ - - } +export async function updateImagenDePerfil() { + try { + } catch {} } diff --git a/src/lib/hooks/updatePost.ts b/src/lib/hooks/updatePost.ts index 7197820..721d0fd 100644 --- a/src/lib/hooks/updatePost.ts +++ b/src/lib/hooks/updatePost.ts @@ -5,9 +5,9 @@ import { sesionStore } from '@/stores/usuario'; export async function updatePost(post: Post, callbackfn: Function, message: string) { try { - const formData = new FormData(); - formData.append("content", post.content); - formData.append("image", post.image||""); + const formData = new FormData(); + formData.append('content', post.content); + formData.append('image', post.image || ''); const req = await fetch(get(apiBase) + `/api/posts/${post.id}`, { method: 'PUT', diff --git a/src/lib/stores/posts.ts b/src/lib/stores/posts.ts index 22823bf..cb19b9b 100644 --- a/src/lib/stores/posts.ts +++ b/src/lib/stores/posts.ts @@ -19,21 +19,14 @@ export const addPost = (post: Post) => { posts.update((current) => [post, ...current]); }; -export const updatePostStore = ( - postId: string, - updatedData: Partial -) => { +export const updatePostStore = (postId: string, updatedData: Partial) => { posts.update((current) => - current.map((post) => - post.id === postId ? { ...post, ...updatedData } : post - ) + current.map((post) => (post.id === postId ? { ...post, ...updatedData } : post)) ); }; export const removePost = (postId: string) => { - posts.update((current) => - current.filter((post) => post.id !== postId) - ); + posts.update((current) => current.filter((post) => post.id !== postId)); }; export const resetPosts = () => { diff --git a/src/lib/utils.ts b/src/lib/utils.ts index 0bdba03..092740a 100644 --- a/src/lib/utils.ts +++ b/src/lib/utils.ts @@ -13,11 +13,11 @@ export type WithoutChildrenOrChild = WithoutChildren>; export type WithElementRef = T & { ref?: U | null }; export function filtrarImagen(file: File) { - if (file) { + if (file) { const allowed = ['image/png', 'image/jpg', 'image/jpeg', 'image/gif', 'image/webp']; if (allowed.includes(file.type)) { return file; } } - return null; + return null; } diff --git a/src/routes/[perfil]/+page.ts b/src/routes/[perfil]/+page.ts index 119d7b2..1678053 100644 --- a/src/routes/[perfil]/+page.ts +++ b/src/routes/[perfil]/+page.ts @@ -1,5 +1,5 @@ import { obtenerUsuarioPorUsername } from '@/hooks/obtenerUsuario.js'; -import type {UserResponseDto } from '../../types.js'; +import type { UserResponseDto } from '../../types.js'; import { error } from '@sveltejs/kit'; import type { PageLoad } from './$types'; import { obtenerSeguidosPorUsuario } from '@/hooks/obtenerSeguidosPorUsuario.js'; @@ -26,4 +26,4 @@ export const load: PageLoad = async ({ params, depends, fetch }) => { countSeguidores: countSeguidores.count, countSeguidos: countSeguidos.count }; -}; \ No newline at end of file +}; diff --git a/src/routes/[perfil]/seguidores/+page.svelte b/src/routes/[perfil]/seguidores/+page.svelte index afa29f2..07153bf 100644 --- a/src/routes/[perfil]/seguidores/+page.svelte +++ b/src/routes/[perfil]/seguidores/+page.svelte @@ -14,7 +14,7 @@ }; let { data }: { data: Data } = $props(); - + let currentPage = $state(1); let isLoading = $state(false); const limit = 100; @@ -23,19 +23,18 @@ async function loadPage(page: number) { if (isLoading) return; - + isLoading = true; const response = await obtenerSeguidoresPorUsuario(data.usuario.id, page, limit); - + if (response) { data.seguidores = response.response as UserResponseDto[]; data.totalCount = response.totalCount; currentPage = page; } - + isLoading = false; } -
@@ -51,7 +50,7 @@
- + {#if isLoading}

Cargando...

@@ -79,11 +78,11 @@ > - + Página {currentPage} de {totalPages} - +
{/if} - \ No newline at end of file + diff --git a/src/routes/[perfil]/seguidores/+page.ts b/src/routes/[perfil]/seguidores/+page.ts index 007f2c1..7f23a42 100644 --- a/src/routes/[perfil]/seguidores/+page.ts +++ b/src/routes/[perfil]/seguidores/+page.ts @@ -19,4 +19,4 @@ export const load: PageLoad = async ({ params, fetch }) => { usuario, seguidores: seguidoresResponse?.response || [] }; -} +}; diff --git a/src/routes/[perfil]/seguidos/+page.svelte b/src/routes/[perfil]/seguidos/+page.svelte index 107efa9..63e4717 100644 --- a/src/routes/[perfil]/seguidos/+page.svelte +++ b/src/routes/[perfil]/seguidos/+page.svelte @@ -14,7 +14,7 @@ }; let { data }: { data: Data } = $props(); - + let currentPage = $state(1); let isLoading = $state(false); const limit = 100; @@ -23,19 +23,18 @@ async function loadPage(page: number) { if (isLoading) return; - + isLoading = true; const response = await obtenerSeguidosPorUsuario(data.usuario.id, page, limit); - + if (response) { data.seguidos = response.response as UserResponseDto[]; data.totalCount = response.totalCount; currentPage = page; } - + isLoading = false; } -
@@ -51,7 +50,7 @@
- + {#if isLoading}

Cargando...

@@ -79,11 +78,11 @@ > - + Página {currentPage} de {totalPages} - +
{/if} - \ No newline at end of file +