mirror of
https://github.com/emailerfacu-spec/minix-front.git
synced 2026-04-03 13:30:42 -03:00
terminada logica de like + rework de la interfaz
This commit is contained in:
21
src/lib/hooks/likePublicacion.ts
Normal file
21
src/lib/hooks/likePublicacion.ts
Normal 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 };
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user