mirror of
https://github.com/emailerfacu-spec/minix-front.git
synced 2026-04-29 17:32:46 -03:00
hecha la pagina de busqueda
This commit is contained in:
@@ -0,0 +1,41 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { resolve } from '$app/paths';
|
||||||
|
import type { UserResponseDto } from '../../types';
|
||||||
|
import AvatarFallback from './ui/avatar/avatar-fallback.svelte';
|
||||||
|
import AvatarImage from './ui/avatar/avatar-image.svelte';
|
||||||
|
import Avatar from './ui/avatar/avatar.svelte';
|
||||||
|
import Button from './ui/button/button.svelte';
|
||||||
|
import CardContent from './ui/card/card-content.svelte';
|
||||||
|
import CardHeader from './ui/card/card-header.svelte';
|
||||||
|
import CardTitle from './ui/card/card-title.svelte';
|
||||||
|
import Card from './ui/card/card.svelte';
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
usu: UserResponseDto;
|
||||||
|
}
|
||||||
|
|
||||||
|
let { usu }: Props = $props();
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<Card class="w-[50%]">
|
||||||
|
<CardContent>
|
||||||
|
<div class="flex justify-between">
|
||||||
|
<a class="flex items-center gap-2" href={resolve(`/${usu.username}`)}>
|
||||||
|
<Avatar>
|
||||||
|
<AvatarImage src={usu.profileImageUrl}></AvatarImage>
|
||||||
|
<AvatarFallback>{usu.displayName[0]}</AvatarFallback>
|
||||||
|
</Avatar>
|
||||||
|
<h4 class="scroll-m-20 text-xl font-semibold tracking-tight">
|
||||||
|
{usu.displayName}
|
||||||
|
</h4>
|
||||||
|
<p class="text-sm text-muted-foreground">@{usu.username}</p>
|
||||||
|
</a>
|
||||||
|
<div>
|
||||||
|
<Button variant="outline">Seguir</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{#if usu.bio}
|
||||||
|
<div class="mt-4 rounded-full bg-accent p-4 text-muted-foreground">{usu.bio}</div>
|
||||||
|
{/if}
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
import { apiBase } from '@/stores/url';
|
||||||
|
import { get } from 'svelte/store';
|
||||||
|
|
||||||
|
export async function busquedaUsuarios(username: string) {
|
||||||
|
if (!username) return null;
|
||||||
|
try {
|
||||||
|
const req = await fetch(`${get(apiBase)}/api/users/search?q=${username}`, {
|
||||||
|
method: 'GET'
|
||||||
|
});
|
||||||
|
if (req.ok) {
|
||||||
|
let data = await req.json();
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
return [];
|
||||||
|
} catch {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
<script>
|
||||||
|
import UserCard from '@/components/UserCard.svelte';
|
||||||
|
|
||||||
|
let { data } = $props();
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div class="flex min-h-fit w-full flex-col items-center justify-center gap-2 p-6 md:p-10">
|
||||||
|
{#each data.usuarios as usu}
|
||||||
|
<UserCard {usu} />
|
||||||
|
{/each}
|
||||||
|
</div>
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
import { busquedaUsuarios } from '@/hooks/busquedaUsuarios';
|
||||||
|
import type { PageProps } from '../$types';
|
||||||
|
import { error } from '@sveltejs/kit';
|
||||||
|
import type { UserResponseDto } from '../../../types';
|
||||||
|
|
||||||
|
export async function load({ params }: PageProps) {
|
||||||
|
let usuarios: UserResponseDto[] = await busquedaUsuarios(params.user);
|
||||||
|
if (usuarios == null) {
|
||||||
|
return error(500, 'No se pudo alcanzar el servidor.');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (usuarios.length == 0) {
|
||||||
|
return error(404, 'No se encontraron usuarios que coinsidan con la busqueda.');
|
||||||
|
}
|
||||||
|
return { usuarios };
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user