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",
"dependencies": {
"mode-watcher": "^1.1.0",
"mode-watcher": "^1.1.0"
},
"devDependencies": {
"@internationalized/date": "^3.8.1",
@@ -25,9 +25,9 @@
"tailwindcss": "^4.1.14",
"tw-animate-css": "^1.4.0",
"typescript": "^5.9.3",
"vite": "^7.1.10",
},
},
"vite": "^7.1.10"
}
}
},
"packages": {
"@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/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 { sesionStore } from '@/stores/usuario';
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();
@@ -43,9 +46,8 @@
hoverimg = false;
}
</script>
<!-- <Button onclick={() => (cargando = !cargando)}>a</Button> -->
<Card class="mb-2 flex w-3/4 overflow-hidden">
<!-- {$inspect(data)} -->
<Card class="mb-2 flex overflow-hidden">
<CardContent>
{#if cargando}
<div class="flex flex-col items-center space-y-4">
@@ -54,31 +56,34 @@
<Skeleton class="h-16 w-3/4 rounded-full" />
</div>
{:else if $sesionStore?.isAdmin || $sesionStore?.username == data.username}
<button
class="relative flex w-full items-center justify-center"
onmouseenter={() => (hoverimg = true)}
onmouseleave={() => (hoverimg = false)}
onclick={cambiarFotoDePerfil}
>
<Avatar
class={{
'brightness-0': hoverimg,
'relative z-0 mt-2 scale-250 border-2 border-slate-950 transition-all': true
}}
>
<AvatarImage src={data.imageUrl} alt="Imagen de perfil"></AvatarImage>
<AvatarFallback class="select-none">
{data.displayName?.[0]?.toUpperCase() || ''}
</AvatarFallback>
</Avatar>
<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:opacity-100={hoverimg}
class:opacity-0={!hoverimg}
>
<Pen class="text-white" />
</div>
</button>
<div class="w-full flex justify-center">
<button
class="relative flex items-center justify-center"
onmouseenter={() => (hoverimg = true)}
onmouseleave={() => (hoverimg = false)}
onclick={cambiarFotoDePerfil}
>
<Avatar
class={{
'brightness-0': hoverimg,
'relative z-0 mt-2 scale-250 border-2 border-slate-950 transition-all': true
}}
>
<AvatarImage src={data.imageUrl} alt="Imagen de perfil"></AvatarImage>
<AvatarFallback class="select-none">
{data.displayName?.[0]?.toUpperCase() || ''}
</AvatarFallback>
</Avatar>
<div
class="absolute inset-0 flex justify-center items-center"
class:opacity-100={hoverimg}
class:opacity-0={!hoverimg}
>
<Pen class="text-white" />
</div>
</button>
</div>
<h1 class="mt-10 scroll-m-20 text-center text-2xl font-extrabold tracking-tight lg:text-5xl">
{data.displayName}
<p class="ml-2 text-2xl font-medium text-muted-foreground">@{data.username}</p>
@@ -106,6 +111,46 @@
<p class="mt-4 rounded-full bg-accent p-4 text-center text-muted-foreground">
{data.bio}
</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>
</Card>

View File

@@ -1,25 +1,28 @@
import { sesionStore } from "@/stores/usuario";
import type { UserResponseDto } from "../../types";
import { get } from "svelte/store";
import { apiBase } from "@/stores/url";
import { sesionStore } from '@/stores/usuario';
import type { UsersResponseDto } from '../../types';
import { get } from 'svelte/store';
import { apiBase } from '@/stores/url';
export async function obtenerSeguidoresPorUsuario(id: string, limit:number = 20): Promise<UserResponseDto[] | null> {
try {
const response = await fetch(`${get(apiBase)}/api/users/${id}/followers?limit=${limit}`, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${get(sesionStore)?.accessToken}`
}
});
export async function obtenerSeguidoresPorUsuario(
id: string,
limit: number = 20
): Promise<UsersResponseDto | null> {
try {
const response = await fetch(`${get(apiBase)}/api/users/${id}/followers?limit=${limit}`, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${get(sesionStore)?.accessToken}`
}
});
if (!response.ok) {
return null;
}
if (!response.ok) {
return null;
}
const followers: UserResponseDto[] = await response.json();
return followers;
} catch (error) {
return null;
}
const followers: UsersResponseDto = await response.json();
return followers;
} catch (error) {
return null;
}
}

View File

@@ -1,25 +1,28 @@
import { sesionStore } from "@/stores/usuario";
import type { UserResponseDto } from "../../types";
import { apiBase } from "@/stores/url";
import { get } from "svelte/store";
import { sesionStore } from '@/stores/usuario';
import type { UsersResponseDto } from '../../types';
import { apiBase } from '@/stores/url';
import { get } from 'svelte/store';
export async function obtenerSeguidosPorUsuario(id: string, limit:number = 20): Promise<UserResponseDto[] | null> {
try {
const response = await fetch(`${get(apiBase)}/api/users/${id}/following?limit=${limit}`, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${get(sesionStore)?.accessToken}`
}
});
export async function obtenerSeguidosPorUsuario(
id: string,
limit: number = 20
): Promise<UsersResponseDto | null> {
try {
const response = await fetch(`${get(apiBase)}/api/users/${id}/following?limit=${limit}`, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${get(sesionStore)?.accessToken}`
}
});
if (!response.ok) {
return null;
}
if (!response.ok) {
return null;
}
const users: UserResponseDto[] = await response.json();
return users;
} catch (error) {
return null;
}
const users: UsersResponseDto = await response.json();
return users;
} catch (error) {
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="w-full max-w-6xl">
<div class="flex gap-2">
<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
class="mt-10 flex scroll-m-20 justify-between text-3xl font-extrabold tracking-tight lg:text-3xl"
>

View File

@@ -5,11 +5,13 @@ 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);
if(!usuario) error(404, 'No se encontro el usuario, ' + params.perfil);
const usuario: UserResponseDto | null = await obtenerUsuarioPorUsername(params.perfil);
if (!usuario) error(404, 'No se encontro el usuario, ' + params.perfil);
const seguidos = await obtenerSeguidosPorUsuario(usuario.id, 3);
const seguidores = await obtenerSeguidoresPorUsuario(usuario.id, 3);
const [seguidos, seguidores] = await Promise.all([
obtenerSeguidosPorUsuario(usuario.id, 3),
obtenerSeguidoresPorUsuario(usuario.id, 3)
]);
return { ...usuario, seguidos, seguidores };
return { ...usuario, seguidos, seguidores };
}

28
src/types.d.ts vendored
View File

@@ -84,18 +84,34 @@ export interface UserResponseDto {
displayName: string;
email: string;
bio: string;
imageUrl: string?;
imageUrl: string?;
profileImageUrl: string;
followersCount: number;
followingCount: number;
createdAt: string;
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 {
username: string?;
displayName: string?;
bio: string?;
email: string?;
profileImage: File?;
username: string?;
displayName: string?;
bio: string?;
email: string?;
profileImage: File?;
}