diff --git a/src/lib/components/DialogModificarUsuario.svelte b/src/lib/components/DialogModificarUsuario.svelte index f20b6fa..1d6403f 100644 --- a/src/lib/components/DialogModificarUsuario.svelte +++ b/src/lib/components/DialogModificarUsuario.svelte @@ -1,27 +1,27 @@ - -
- -
-
-
- - - -

Modificar Usuario

-
-
- - - - Nombre - - - - - - bio - - - - - Email - - - - - - -
-
+ +
+ +
+
+
+ + + +

Modificar Usuario

+
+
+ + + Nombre + + + + bio + + + + Email + + + + + + +
+
diff --git a/src/lib/hooks/obtenerSeguidoresPorUsuario.ts b/src/lib/hooks/obtenerSeguidoresPorUsuario.ts index bec0430..3c84b05 100644 --- a/src/lib/hooks/obtenerSeguidoresPorUsuario.ts +++ b/src/lib/hooks/obtenerSeguidoresPorUsuario.ts @@ -5,10 +5,12 @@ import { apiBase } from '@/stores/url'; export async function obtenerSeguidoresPorUsuario( id: string, - limit: number = 20 + limit: number = 20, + fetch2: Function ): Promise { try { - const response = await fetch(`${get(apiBase)}/api/users/${id}/followers?limit=${limit}`, { + const fetchFunc = fetch2 || fetch; + const response = await fetchFunc(`${get(apiBase)}/api/users/${id}/followers?limit=${limit}`, { method: 'GET', headers: { 'Content-Type': 'application/json', diff --git a/src/lib/hooks/obtenerSeguidosPorUsuario.ts b/src/lib/hooks/obtenerSeguidosPorUsuario.ts index 160f075..1db413b 100644 --- a/src/lib/hooks/obtenerSeguidosPorUsuario.ts +++ b/src/lib/hooks/obtenerSeguidosPorUsuario.ts @@ -5,10 +5,13 @@ import { get } from 'svelte/store'; export async function obtenerSeguidosPorUsuario( id: string, - limit: number = 20 + limit: number = 20, + fetch2?: Function ): Promise { try { - const response = await fetch(`${get(apiBase)}/api/users/${id}/following?limit=${limit}`, { + const fetchFunc = fetch2 || fetch; + + const response = await fetchFunc(`${get(apiBase)}/api/users/${id}/following?limit=${limit}`, { method: 'GET', headers: { 'Content-Type': 'application/json', diff --git a/src/lib/hooks/obtenerUsuario.ts b/src/lib/hooks/obtenerUsuario.ts index 40481bf..c519c59 100644 --- a/src/lib/hooks/obtenerUsuario.ts +++ b/src/lib/hooks/obtenerUsuario.ts @@ -3,9 +3,14 @@ import type { UserResponseDto } from '../../types'; import { get } from 'svelte/store'; import { sesionStore } from '@/stores/usuario'; -export async function obtenerUsuarioPorUsername(username: string): Promise { +export async function obtenerUsuarioPorUsername( + username: string, + fetch2?: Function +): Promise { try { - const response = await fetch(`${get(apiBase)}/api/users/username/${username}`, { + const fetchFunction = fetch2 || fetch; + + const response = await fetchFunction(`${get(apiBase)}/api/users/username/${username}`, { method: 'GET', headers: { 'Content-Type': 'application/json', diff --git a/src/routes/[perfil]/+page.svelte b/src/routes/[perfil]/+page.svelte index 6415421..fada5c4 100644 --- a/src/routes/[perfil]/+page.svelte +++ b/src/routes/[perfil]/+page.svelte @@ -28,13 +28,7 @@ let showCrearPost = $state(false); const toggleCrearPost = () => (showCrearPost = !showCrearPost); - const { subscribe } = apiBase; - let baseUrl: string = ''; - let data = $state(page.data); - - subscribe((value) => { - baseUrl = value; - })(); + let data = $derived(page.data); $effect(() => { obtenerPosts(); @@ -42,7 +36,7 @@ async function obtenerPosts() { try { - const req = await fetch(baseUrl + '/api/posts/user/' + params.perfil, { + const req = await fetch($apiBase + '/api/posts/user/' + params.perfil, { method: 'GET', headers: { Authorization: `Bearer ${$sesionStore?.accessToken}` @@ -72,10 +66,13 @@ postAModificar = null; } -{$inspect(data)} + +
+ {#key data} + {/key}

diff --git a/src/routes/[perfil]/+page.ts b/src/routes/[perfil]/+page.ts index b91cd9d..f678027 100644 --- a/src/routes/[perfil]/+page.ts +++ b/src/routes/[perfil]/+page.ts @@ -4,13 +4,14 @@ import { error } from '@sveltejs/kit'; import { obtenerSeguidosPorUsuario } from '@/hooks/obtenerSeguidosPorUsuario.js'; import { obtenerSeguidoresPorUsuario } from '@/hooks/obtenerSeguidoresPorUsuario.js'; -export async function load({ params }) { - const usuario: UserResponseDto | null = await obtenerUsuarioPorUsername(params.perfil); +export async function load({ params, depends, fetch }) { + depends('perfil:general'); + const usuario: UserResponseDto | null = await obtenerUsuarioPorUsername(params.perfil, fetch); if (!usuario) error(404, 'No se encontro el usuario, ' + params.perfil); const [seguidos, seguidores] = await Promise.all([ - obtenerSeguidosPorUsuario(usuario.id, 3), - obtenerSeguidoresPorUsuario(usuario.id, 3) + obtenerSeguidosPorUsuario(usuario.id, 3, fetch), + obtenerSeguidoresPorUsuario(usuario.id, 3, fetch) ]); return { ...usuario, seguidos, seguidores };