diff --git a/src/lib/components/admin/AgregarUsuario.svelte b/src/lib/components/admin/AgregarUsuario.svelte index f8a5e62..d016b3a 100644 --- a/src/lib/components/admin/AgregarUsuario.svelte +++ b/src/lib/components/admin/AgregarUsuario.svelte @@ -8,6 +8,7 @@ import Spinner from '../ui/spinner/spinner.svelte'; import { register } from '@/hooks/register'; import type { RegisterDto } from '../../../types'; + import { invalidate } from '$app/navigation'; interface Prop { open: boolean; @@ -29,9 +30,18 @@ cargando = true; error = ''; - await register(e, dto, () => { - error = 'Error al registrar el usuario'; - }); + await register( + e, + dto, + () => { + error = 'Error al registrar el usuario'; + }, + true + ); + if (error == '') { + invalidate('admin:load'); + open = false; + } cargando = false; } @@ -57,11 +67,7 @@ - + Email @@ -71,11 +77,7 @@ - + ContraseƱa @@ -90,11 +92,7 @@ {/if} - diff --git a/src/lib/head/Busqueda.svelte b/src/lib/head/Busqueda.svelte index 3a6134d..12a8b22 100644 --- a/src/lib/head/Busqueda.svelte +++ b/src/lib/head/Busqueda.svelte @@ -19,6 +19,7 @@ import Label from '@/components/ui/label/label.svelte'; import { resolve } from '$app/paths'; import { busquedaHashtags } from '@/hooks/busquedaHashtags'; + import Separator from '@/components/ui/separator/separator.svelte'; let search: string = $state(''); let open = $state(false); @@ -55,16 +56,18 @@ - + + + (open = true)} - class="max-w-0 transition-[max-width] duration-1000 ease-out group-hover:max-w-xs focus:max-w-xs" + class="max-w-0 p-1! transition-[max-width] duration-1000 ease-out group-hover:max-w-xs focus:max-w-xs" /> - - Ctrl+K + + Ctrl+K diff --git a/src/lib/head/Header.svelte b/src/lib/head/Header.svelte index 838fbd1..b403ae7 100644 --- a/src/lib/head/Header.svelte +++ b/src/lib/head/Header.svelte @@ -52,14 +52,14 @@
-
diff --git a/src/lib/hooks/register.ts b/src/lib/hooks/register.ts index 531b7dc..8ee2117 100644 --- a/src/lib/hooks/register.ts +++ b/src/lib/hooks/register.ts @@ -1,36 +1,38 @@ -import { apiBase } from "@/stores/url"; -import { goto } from "$app/navigation"; -import type { RegisterDto } from "../../types"; +import { apiBase } from '@/stores/url'; +import { goto } from '$app/navigation'; +import type { RegisterDto } from '../../types'; +import { get } from 'svelte/store'; -export async function register(e: SubmitEvent, dto: RegisterDto, callbackfn:()=>void){ - e.preventDefault(); - if (dto.password == "" || dto.username == "" || - !dto.email?.includes("@") || dto.displayName=="") return; - try { - - const { subscribe } = apiBase; - let baseUrl: string = ''; - - subscribe((value) => { - baseUrl = value; - })(); - const req = await fetch(baseUrl + "/api/auth/register", { - method: "POST", - headers:{ - "Content-Type": "application/json" - }, - body: JSON.stringify(dto) - }); - if (req.ok) { - const data= await req.json(); - goto("/login?msg="+data.message); - } else { - callbackfn(); - } - - } catch { - callbackfn(); - console.error("fallo al intentar alcanzar el servidor") - - } +export async function register( + e: SubmitEvent, + dto: RegisterDto, + callbackfn: () => void, + admin: boolean = false +) { + e.preventDefault(); + if ( + dto.password == '' || + dto.username == '' || + !dto.email?.includes('@') || + dto.displayName == '' + ) + return; + try { + const req = await fetch(get(apiBase) + '/api/auth/register', { + method: 'POST', + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify(dto) + }); + if (req.ok) { + const data = await req.json(); + if (!admin) goto('/login?msg=' + data.message); + } else { + callbackfn(); + } + } catch { + callbackfn(); + console.error('fallo al intentar alcanzar el servidor'); + } } diff --git a/src/lib/stores/url.ts b/src/lib/stores/url.ts index 7a0bd63..a7e7a33 100644 --- a/src/lib/stores/url.ts +++ b/src/lib/stores/url.ts @@ -1,6 +1,12 @@ import { dev } from '$app/environment'; import { readable } from 'svelte/store'; +// export const apiBase = readable( +// dev ? 'http://localhost:5000' : 'https://minix-back-dsuk.onrender.com' +// ); + export const apiBase = readable( - dev ? 'http://localhost:5000' : 'https://minix-back-dsuk.onrender.com' + dev + ? 'http://localhost:5000' + : 'https://minix-back-3.salmonpebble-66858787.brazilsouth.azurecontainerapps.io' ); diff --git a/src/routes/(privado)/admin/+page.svelte b/src/routes/(privado)/admin/+page.svelte index c7df333..d1bea2a 100644 --- a/src/routes/(privado)/admin/+page.svelte +++ b/src/routes/(privado)/admin/+page.svelte @@ -6,14 +6,21 @@ import TablaUsuarios from '@/components/TablaUsuarios.svelte'; import CardTitle from '@/components/ui/card/card-title.svelte'; import CardHeader from '@/components/ui/card/card-header.svelte'; + import type { UserResponseDto } from '../../../types'; - let cargando = $state(true); - let usuarios = $state(page.data.usuarios); + interface Prop { + data: { + usuarios?: UserResponseDto[]; + error: boolean; + }; + } + + let { data }: Prop = $props();
- +

@@ -22,12 +29,10 @@ - {#if page.data.usuarios.length === 0} + {#if data.usuarios?.length === 0} No hay usuarios que mostar {:else} - {#key page.data.usuarios} - - {/key} + {/if} diff --git a/src/types.d.ts b/src/types.d.ts index f0d647e..1ebbe92 100644 --- a/src/types.d.ts +++ b/src/types.d.ts @@ -1,5 +1,4 @@ export interface Post { - _id: string; id: string; authorId: string; authorDisplayName: string; @@ -76,6 +75,7 @@ export interface PostResponseDto { isEdited: boolean; visibility: string; hashtags: string[]?; + isLiked: boolean?; } export interface UserResponseDto {