mirror of
https://github.com/emailerfacu-spec/minix-front.git
synced 2026-04-21 16:27:32 -03:00
skeleton de la interfaz de seguidores y seguidos
This commit is contained in:
50
src/lib/components/ui/badge/badge.svelte
Normal file
50
src/lib/components/ui/badge/badge.svelte
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
<script lang="ts" module>
|
||||||
|
import { type VariantProps, tv } from "tailwind-variants";
|
||||||
|
|
||||||
|
export const badgeVariants = tv({
|
||||||
|
base: "focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive inline-flex w-fit shrink-0 items-center justify-center gap-1 overflow-hidden whitespace-nowrap rounded-full border px-2 py-0.5 text-xs font-medium transition-[color,box-shadow] focus-visible:ring-[3px] [&>svg]:pointer-events-none [&>svg]:size-3",
|
||||||
|
variants: {
|
||||||
|
variant: {
|
||||||
|
default:
|
||||||
|
"bg-primary text-primary-foreground [a&]:hover:bg-primary/90 border-transparent",
|
||||||
|
secondary:
|
||||||
|
"bg-secondary text-secondary-foreground [a&]:hover:bg-secondary/90 border-transparent",
|
||||||
|
destructive:
|
||||||
|
"bg-destructive [a&]:hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/70 border-transparent text-white",
|
||||||
|
outline: "text-foreground [a&]:hover:bg-accent [a&]:hover:text-accent-foreground",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
defaultVariants: {
|
||||||
|
variant: "default",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
export type BadgeVariant = VariantProps<typeof badgeVariants>["variant"];
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<script lang="ts">
|
||||||
|
import type { HTMLAnchorAttributes } from "svelte/elements";
|
||||||
|
import { cn, type WithElementRef } from "$lib/utils.js";
|
||||||
|
|
||||||
|
let {
|
||||||
|
ref = $bindable(null),
|
||||||
|
href,
|
||||||
|
class: className,
|
||||||
|
variant = "default",
|
||||||
|
children,
|
||||||
|
...restProps
|
||||||
|
}: WithElementRef<HTMLAnchorAttributes> & {
|
||||||
|
variant?: BadgeVariant;
|
||||||
|
} = $props();
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<svelte:element
|
||||||
|
this={href ? "a" : "span"}
|
||||||
|
bind:this={ref}
|
||||||
|
data-slot="badge"
|
||||||
|
{href}
|
||||||
|
class={cn(badgeVariants({ variant }), className)}
|
||||||
|
{...restProps}
|
||||||
|
>
|
||||||
|
{@render children?.()}
|
||||||
|
</svelte:element>
|
||||||
2
src/lib/components/ui/badge/index.ts
Normal file
2
src/lib/components/ui/badge/index.ts
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
export { default as Badge } from "./badge.svelte";
|
||||||
|
export { badgeVariants, type BadgeVariant } from "./badge.svelte";
|
||||||
25
src/lib/hooks/obtenerSeguidoresPorUsuario.ts
Normal file
25
src/lib/hooks/obtenerSeguidoresPorUsuario.ts
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
import { sesionStore } from "@/stores/usuario";
|
||||||
|
import type { UserResponseDto } from "../../types";
|
||||||
|
import { get } from "svelte/store";
|
||||||
|
import { apiBase } from "@/stores/url";
|
||||||
|
|
||||||
|
export async function obtenerSeguidoresPorUsuario(Id: string): Promise<UserResponseDto[] | null> {
|
||||||
|
try {
|
||||||
|
const response = await fetch(`${get(apiBase)}/api/users/${Id}/followers`, {
|
||||||
|
method: 'GET',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
Authorization: `Bearer ${get(sesionStore)?.accessToken}`
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const followers: UserResponseDto[] = await response.json();
|
||||||
|
return followers;
|
||||||
|
} catch (error) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
25
src/lib/hooks/obtenerSeguidosPorUsuario.ts
Normal file
25
src/lib/hooks/obtenerSeguidosPorUsuario.ts
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
import { sesionStore } from "@/stores/usuario";
|
||||||
|
import type { UserResponseDto } from "../../types";
|
||||||
|
import { apiBase } from "@/stores/url";
|
||||||
|
import { get } from "svelte/store";
|
||||||
|
|
||||||
|
export async function obtenerSeguidosPorUsuario(id: string): Promise<UserResponseDto[] | null> {
|
||||||
|
try {
|
||||||
|
const response = await fetch(`${get(apiBase)}/api/users/${id}/following`, {
|
||||||
|
method: 'GET',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
Authorization: `Bearer ${get(sesionStore)?.accessToken}`
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const users: UserResponseDto[] = await response.json();
|
||||||
|
return users;
|
||||||
|
} catch (error) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,11 +1,15 @@
|
|||||||
import { obtenerUsuarioPorUsername } from '@/hooks/obtenerUsuario.js';
|
import { obtenerUsuarioPorUsername } from '@/hooks/obtenerUsuario.js';
|
||||||
import type { User, UserResponseDto } from '../../types.js';
|
import type { User, UserResponseDto } from '../../types.js';
|
||||||
import { error } from '@sveltejs/kit';
|
import { error } from '@sveltejs/kit';
|
||||||
|
import { obtenerSeguidosPorUsuario } from '@/hooks/obtenerSeguidosPorUsuario.js';
|
||||||
|
import { obtenerSeguidoresPorUsuario } from '@/hooks/obtenerSeguidoresPorUsuario.js';
|
||||||
|
|
||||||
export async function load({ params }) {
|
export async function load({ params }) {
|
||||||
const usuario: UserResponseDto | null = await obtenerUsuarioPorUsername(params.perfil);
|
const usuario: UserResponseDto | null = await obtenerUsuarioPorUsername(params.perfil);
|
||||||
if (usuario) {
|
if(!usuario) error(404, 'No se encontro el usuario, ' + params.perfil);
|
||||||
return usuario;
|
|
||||||
}
|
const seguidos = await obtenerSeguidosPorUsuario(usuario.id);
|
||||||
error(404, 'No se encontro el usuario, ' + params.perfil);
|
const seguidores = await obtenerSeguidoresPorUsuario(usuario.id);
|
||||||
|
|
||||||
|
return { ...usuario, seguidos, seguidores };
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,6 +22,9 @@
|
|||||||
import DialogHeader from '@/components/ui/dialog/dialog-header.svelte';
|
import DialogHeader from '@/components/ui/dialog/dialog-header.svelte';
|
||||||
import DialogTitle from '@/components/ui/dialog/dialog-title.svelte';
|
import DialogTitle from '@/components/ui/dialog/dialog-title.svelte';
|
||||||
import { sesionStore } from '@/stores/usuario.js';
|
import { sesionStore } from '@/stores/usuario.js';
|
||||||
|
import CardHeader from '@/components/ui/card/card-header.svelte';
|
||||||
|
import CardTitle from '@/components/ui/card/card-title.svelte';
|
||||||
|
import Badge from '@/components/ui/badge/badge.svelte';
|
||||||
|
|
||||||
let { params } = $props();
|
let { params } = $props();
|
||||||
|
|
||||||
@@ -62,7 +65,6 @@
|
|||||||
|
|
||||||
async function handleEditar(e: SubmitEvent) {
|
async function handleEditar(e: SubmitEvent) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
// post.content = 'test';
|
|
||||||
if (postAModificar == null) return;
|
if (postAModificar == null) return;
|
||||||
await updatePost(
|
await updatePost(
|
||||||
postAModificar,
|
postAModificar,
|
||||||
@@ -76,12 +78,13 @@
|
|||||||
|
|
||||||
<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">
|
||||||
<Card class="mb-2 overflow-hidden">
|
<div class="flex gap-2">
|
||||||
|
<Card class="mb-2 flex w-3/4 overflow-hidden">
|
||||||
<CardContent>
|
<CardContent>
|
||||||
<div class="flex justify-center">
|
<div class="flex justify-center">
|
||||||
<Avatar class="mt-2 scale-250 border-2 border-slate-950">
|
<Avatar class="mt-2 scale-250 border-2 border-slate-950">
|
||||||
<AvatarImage></AvatarImage>
|
<AvatarImage></AvatarImage>
|
||||||
<AvatarFallback>{page.data.displayName[0].toUpperCase()}</AvatarFallback>
|
<AvatarFallback>{page.data.displayName?.[0]?.toUpperCase() || ''}</AvatarFallback>
|
||||||
</Avatar>
|
</Avatar>
|
||||||
</div>
|
</div>
|
||||||
<h1
|
<h1
|
||||||
@@ -92,8 +95,36 @@
|
|||||||
<h3 class="scroll-m-20 text-center text-2xl tracking-tight text-muted-foreground">
|
<h3 class="scroll-m-20 text-center text-2xl tracking-tight text-muted-foreground">
|
||||||
@{params.perfil}
|
@{params.perfil}
|
||||||
</h3>
|
</h3>
|
||||||
|
<p class="mt-4 rounded-full bg-accent p-4 text-center text-muted-foreground">
|
||||||
|
{page.data.bio}
|
||||||
|
</p>
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
|
<aside class="flex w-1/4 flex-col gap-2">
|
||||||
|
<Card class="w-full">
|
||||||
|
<CardContent>
|
||||||
|
<CardHeader class="flex justify-between">
|
||||||
|
<CardTitle>Seguidores:</CardTitle>
|
||||||
|
<Badge variant="secondary">{page.data.seguidos.length}</Badge>
|
||||||
|
</CardHeader>
|
||||||
|
<CardContent>
|
||||||
|
<!-- Seguidos -->
|
||||||
|
</CardContent>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
<Card class="w-full">
|
||||||
|
<CardContent>
|
||||||
|
<CardHeader class="flex justify-between">
|
||||||
|
<CardTitle>Seguidos:</CardTitle>
|
||||||
|
<Badge variant="secondary">{page.data.seguidores.length}</Badge>
|
||||||
|
</CardHeader>
|
||||||
|
<CardContent>
|
||||||
|
<!-- Seguidores -->
|
||||||
|
</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"
|
||||||
|
|||||||
Reference in New Issue
Block a user