hecha functionalidad para seguir usuarios desde los posts

This commit is contained in:
2026-01-07 16:05:42 -03:00
parent d98e06ca31
commit d3a9bb7405
6 changed files with 251 additions and 2 deletions

View File

@@ -0,0 +1,26 @@
import { sesionStore } from '@/stores/usuario';
import { get } from 'svelte/store';
import type { Post } from '../../types';
import { apiBase } from '@/stores/url';
export async function esSeguido(post: Post) {
if (!get(sesionStore)?.accessToken || post.authorName === '[deleted]') return;
const id = post.authorId;
try {
const response = await fetch(`${get(apiBase)}/api/users/${id}/is-following`, {
headers: {
Authorization: `Bearer ${get(sesionStore)?.accessToken}`
}
});
if (response.ok) {
const data = await response.json();
return data;
} else {
return false;
}
} catch {
return null;
}
}

View File

@@ -0,0 +1,21 @@
import { apiBase } from '@/stores/url';
import { sesionStore } from '@/stores/usuario';
import { get } from 'svelte/store';
export async function seguirUsuario(idusuario: string, toggle: Boolean = false) {
try {
const req = await fetch(`${get(apiBase)}/api/users/${idusuario}/follow`, {
method: !toggle ? 'POST' : 'DELETE',
headers: {
Authorization: `Bearer ${get(sesionStore)?.accessToken}`
}
});
if (req.ok) {
return true;
} else {
return false;
}
} catch {
return null;
}
}