mirror of
https://github.com/emailerfacu-spec/minix-front.git
synced 2026-04-15 15:30:44 -03:00
hecha functionalidad para seguir usuarios desde los posts
This commit is contained in:
26
src/lib/hooks/esSeguido.ts
Normal file
26
src/lib/hooks/esSeguido.ts
Normal 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;
|
||||
}
|
||||
}
|
||||
21
src/lib/hooks/seguirUsuario.ts
Normal file
21
src/lib/hooks/seguirUsuario.ts
Normal 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user