terminada logica de like + rework de la interfaz

This commit is contained in:
2025-11-30 00:16:28 -03:00
parent 3068280b82
commit 78e7df318e
3 changed files with 72 additions and 12 deletions

View File

@@ -0,0 +1,21 @@
import { apiBase } from '@/stores/url';
import { get } from 'svelte/store';
import { sesionStore } from '@/stores/usuario';
import type { Post } from '../../types';
export async function likePublicacion(post: Post) {
try {
const req = await fetch(get(apiBase) + `/api/posts/${post.id}/like`, {
method: post.isLiked ? 'DELETE' : 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${get(sesionStore)?.accessToken}`
}
});
const data: { message: string } = await req.json();
return { message: data.message, ok: req.ok };
} catch {
return { message: 'No se pudo alcanzar el servidor', ok: false };
}
}