algunos arreglos a la ui y correjido un cambio en una api

This commit is contained in:
2025-12-22 20:19:42 -03:00
parent ae381c00ff
commit 252e1d0b98
7 changed files with 156 additions and 130 deletions

View File

@@ -4,7 +4,7 @@
"": { "": {
"name": "mini-x-front", "name": "mini-x-front",
"dependencies": { "dependencies": {
"mode-watcher": "^1.1.0", "mode-watcher": "^1.1.0"
}, },
"devDependencies": { "devDependencies": {
"@internationalized/date": "^3.8.1", "@internationalized/date": "^3.8.1",
@@ -25,9 +25,9 @@
"tailwindcss": "^4.1.14", "tailwindcss": "^4.1.14",
"tw-animate-css": "^1.4.0", "tw-animate-css": "^1.4.0",
"typescript": "^5.9.3", "typescript": "^5.9.3",
"vite": "^7.1.10", "vite": "^7.1.10"
}, }
}, }
}, },
"packages": { "packages": {
"@esbuild/aix-ppc64": ["@esbuild/aix-ppc64@0.25.12", "", { "os": "aix", "cpu": "ppc64" }, "sha512-Hhmwd6CInZ3dwpuGTF8fJG6yoWmsToE+vYgD4nytZVxcu1ulHpUQRAB1UJ8+N1Am3Mz4+xOByoQoSZf4D+CpkA=="], "@esbuild/aix-ppc64": ["@esbuild/aix-ppc64@0.25.12", "", { "os": "aix", "cpu": "ppc64" }, "sha512-Hhmwd6CInZ3dwpuGTF8fJG6yoWmsToE+vYgD4nytZVxcu1ulHpUQRAB1UJ8+N1Am3Mz4+xOByoQoSZf4D+CpkA=="],
@@ -490,6 +490,6 @@
"wrap-ansi-cjs/string-width/emoji-regex": ["emoji-regex@8.0.0", "", {}, "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A=="], "wrap-ansi-cjs/string-width/emoji-regex": ["emoji-regex@8.0.0", "", {}, "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A=="],
"wrap-ansi-cjs/strip-ansi/ansi-regex": ["ansi-regex@5.0.1", "", {}, "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ=="], "wrap-ansi-cjs/strip-ansi/ansi-regex": ["ansi-regex@5.0.1", "", {}, "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ=="]
} }
} }

View File

@@ -11,6 +11,9 @@
import { updateUsuario } from '@/hooks/updateUsuario'; import { updateUsuario } from '@/hooks/updateUsuario';
import { sesionStore } from '@/stores/usuario'; import { sesionStore } from '@/stores/usuario';
import { obtenerUsuarioPorUsername } from '@/hooks/obtenerUsuario'; import { obtenerUsuarioPorUsername } from '@/hooks/obtenerUsuario';
import CardHeader from './ui/card/card-header.svelte';
import CardTitle from './ui/card/card-title.svelte';
import Badge from './ui/badge/badge.svelte';
let { data = $bindable() } = $props(); let { data = $bindable() } = $props();
@@ -43,9 +46,8 @@
hoverimg = false; hoverimg = false;
} }
</script> </script>
<!-- {$inspect(data)} -->
<!-- <Button onclick={() => (cargando = !cargando)}>a</Button> --> <Card class="mb-2 flex overflow-hidden">
<Card class="mb-2 flex w-3/4 overflow-hidden">
<CardContent> <CardContent>
{#if cargando} {#if cargando}
<div class="flex flex-col items-center space-y-4"> <div class="flex flex-col items-center space-y-4">
@@ -54,8 +56,9 @@
<Skeleton class="h-16 w-3/4 rounded-full" /> <Skeleton class="h-16 w-3/4 rounded-full" />
</div> </div>
{:else if $sesionStore?.isAdmin || $sesionStore?.username == data.username} {:else if $sesionStore?.isAdmin || $sesionStore?.username == data.username}
<div class="w-full flex justify-center">
<button <button
class="relative flex w-full items-center justify-center" class="relative flex items-center justify-center"
onmouseenter={() => (hoverimg = true)} onmouseenter={() => (hoverimg = true)}
onmouseleave={() => (hoverimg = false)} onmouseleave={() => (hoverimg = false)}
onclick={cambiarFotoDePerfil} onclick={cambiarFotoDePerfil}
@@ -72,13 +75,15 @@
</AvatarFallback> </AvatarFallback>
</Avatar> </Avatar>
<div <div
class="absolute inset-0 top-1/2 left-1/2 z-10 flex -translate-x-1/2 -translate-y-1/2 transform items-center justify-center" class="absolute inset-0 flex justify-center items-center"
class:opacity-100={hoverimg} class:opacity-100={hoverimg}
class:opacity-0={!hoverimg} class:opacity-0={!hoverimg}
> >
<Pen class="text-white" /> <Pen class="text-white" />
</div> </div>
</button> </button>
</div>
<h1 class="mt-10 scroll-m-20 text-center text-2xl font-extrabold tracking-tight lg:text-5xl"> <h1 class="mt-10 scroll-m-20 text-center text-2xl font-extrabold tracking-tight lg:text-5xl">
{data.displayName} {data.displayName}
<p class="ml-2 text-2xl font-medium text-muted-foreground">@{data.username}</p> <p class="ml-2 text-2xl font-medium text-muted-foreground">@{data.username}</p>
@@ -107,5 +112,45 @@
{data.bio} {data.bio}
</p> </p>
{/if} {/if}
<div class="flex gap-2 mt-2">
<Card class="w-full">
<CardContent>
<CardHeader class="flex justify-between">
<CardTitle>Seguidos:</CardTitle>
<Badge variant="secondary">{data.seguidos.response.length}</Badge>
</CardHeader>
<CardContent>
{#if data.seguidos.response.length === 0}
<h3>No hay Seguidos</h3>
{:else}
{#each data.seguidos.response as seguidos (seguidos.id)}
<p class="text-muted-foreground">
{seguidos.username}
</p>
{/each}
{/if}
</CardContent>
</CardContent>
</Card>
<Card class="w-full">
<CardContent>
<CardHeader class="flex justify-between">
<CardTitle>Seguidores:</CardTitle>
<Badge variant="secondary">{data.seguidores.response.length}</Badge>
</CardHeader>
<CardContent>
{#if data.seguidores.response.length === 0}
<h3>No hay Seguidores</h3>
{:else}
{#each data.seguidores.response as seguidores (seguidores.id)}
<p class="text-muted-foreground">
{seguidores.username}
</p>
{/each}
{/if}
</CardContent>
</CardContent>
</Card>
</div>
</CardContent> </CardContent>
</Card> </Card>

View File

@@ -1,9 +1,12 @@
import { sesionStore } from "@/stores/usuario"; import { sesionStore } from '@/stores/usuario';
import type { UserResponseDto } from "../../types"; import type { UsersResponseDto } from '../../types';
import { get } from "svelte/store"; import { get } from 'svelte/store';
import { apiBase } from "@/stores/url"; import { apiBase } from '@/stores/url';
export async function obtenerSeguidoresPorUsuario(id: string, limit:number = 20): Promise<UserResponseDto[] | null> { export async function obtenerSeguidoresPorUsuario(
id: string,
limit: number = 20
): Promise<UsersResponseDto | null> {
try { try {
const response = await fetch(`${get(apiBase)}/api/users/${id}/followers?limit=${limit}`, { const response = await fetch(`${get(apiBase)}/api/users/${id}/followers?limit=${limit}`, {
method: 'GET', method: 'GET',
@@ -17,7 +20,7 @@ export async function obtenerSeguidoresPorUsuario(id: string, limit:number = 20)
return null; return null;
} }
const followers: UserResponseDto[] = await response.json(); const followers: UsersResponseDto = await response.json();
return followers; return followers;
} catch (error) { } catch (error) {
return null; return null;

View File

@@ -1,9 +1,12 @@
import { sesionStore } from "@/stores/usuario"; import { sesionStore } from '@/stores/usuario';
import type { UserResponseDto } from "../../types"; import type { UsersResponseDto } from '../../types';
import { apiBase } from "@/stores/url"; import { apiBase } from '@/stores/url';
import { get } from "svelte/store"; import { get } from 'svelte/store';
export async function obtenerSeguidosPorUsuario(id: string, limit:number = 20): Promise<UserResponseDto[] | null> { export async function obtenerSeguidosPorUsuario(
id: string,
limit: number = 20
): Promise<UsersResponseDto | null> {
try { try {
const response = await fetch(`${get(apiBase)}/api/users/${id}/following?limit=${limit}`, { const response = await fetch(`${get(apiBase)}/api/users/${id}/following?limit=${limit}`, {
method: 'GET', method: 'GET',
@@ -17,7 +20,7 @@ export async function obtenerSeguidosPorUsuario(id: string, limit:number = 20):
return null; return null;
} }
const users: UserResponseDto[] = await response.json(); const users: UsersResponseDto = await response.json();
return users; return users;
} catch (error) { } catch (error) {
return null; return null;

View File

@@ -80,50 +80,7 @@
<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">
<div class="w-full max-w-6xl"> <div class="w-full max-w-6xl">
<div class="flex gap-2">
<CardPerfil bind:data /> <CardPerfil bind:data />
<aside class="flex w-1/4 flex-col gap-2">
<Card class="w-full">
<CardContent>
<CardHeader class="flex justify-between">
<CardTitle>Seguidos:</CardTitle>
<Badge variant="secondary">{data.seguidos.length}</Badge>
</CardHeader>
<CardContent>
{#if data.seguidos.length === 0}
<h3>No hay Seguidos</h3>
{:else}
{#each data.seguidos as seguidos (seguidos.id)}
<p class="text-muted-foreground">
{seguidos.username}
</p>
{/each}
{/if}
</CardContent>
</CardContent>
</Card>
<Card class="w-full">
<CardContent>
<CardHeader class="flex justify-between">
<CardTitle>Seguidores:</CardTitle>
<Badge variant="secondary">{data.seguidores.length}</Badge>
</CardHeader>
<CardContent>
{#if data.seguidores.length === 0}
<h3>No hay Seguidores</h3>
{:else}
{#each data.seguidores as seguidores (seguidores.id)}
<p class="text-muted-foreground">
{seguidores.username}
</p>
{/each}
{/if}
</CardContent>
</CardContent>
</Card>
</aside>
</div>
<h1 <h1
class="mt-10 flex scroll-m-20 justify-between text-3xl font-extrabold tracking-tight lg:text-3xl" class="mt-10 flex scroll-m-20 justify-between text-3xl font-extrabold tracking-tight lg:text-3xl"
> >

View File

@@ -8,8 +8,10 @@ export async function load({ params }) {
const usuario: UserResponseDto | null = await obtenerUsuarioPorUsername(params.perfil); const usuario: UserResponseDto | null = await obtenerUsuarioPorUsername(params.perfil);
if (!usuario) error(404, 'No se encontro el usuario, ' + params.perfil); if (!usuario) error(404, 'No se encontro el usuario, ' + params.perfil);
const seguidos = await obtenerSeguidosPorUsuario(usuario.id, 3); const [seguidos, seguidores] = await Promise.all([
const seguidores = await obtenerSeguidoresPorUsuario(usuario.id, 3); obtenerSeguidosPorUsuario(usuario.id, 3),
obtenerSeguidoresPorUsuario(usuario.id, 3)
]);
return { ...usuario, seguidos, seguidores }; return { ...usuario, seguidos, seguidores };
} }

16
src/types.d.ts vendored
View File

@@ -91,6 +91,22 @@ export interface UserResponseDto {
createdAt: string; createdAt: string;
postsCount: number; postsCount: number;
} }
export interface UsersResponseDto {
response: {
id: string;
username: string;
displayName: string;
email: string;
bio: string;
imageUrl?: string;
profileImageUrl: string;
followersCount: number;
followingCount: number;
createdAt: string;
postsCount: number;
}[];
totalCount: number;
}
export interface UpdateUserRequest { export interface UpdateUserRequest {
username: string?; username: string?;