chore: movi el getPosts a hooks/ y le agrege un header

This commit is contained in:
2025-12-03 15:04:31 -03:00
parent 6ac942fde0
commit 18670e62dd
2 changed files with 18 additions and 14 deletions

17
src/lib/hooks/getPosts.ts Normal file
View File

@@ -0,0 +1,17 @@
import { apiBase } from "@/stores/url";
import { sesionStore } from "@/stores/usuario";
import { get } from "svelte/store";
export async function getPosts() {
const req = await fetch(`${get(apiBase)}/timeline?pageSize=20`,{
headers: {
Authorization: `Bearer ${get(sesionStore)?.accessToken}`
}
});
if (req.ok) {
return await req.json();
}
}

View File

@@ -10,6 +10,7 @@
import ModalEditar from './[perfil]/modalEditar.svelte';
import { updatePost } from '@/hooks/updatePost';
import { fade, slide } from 'svelte/transition';
import { getPosts } from '@/hooks/getPosts';
$effect(() => {
(async () => {
@@ -17,20 +18,6 @@
})();
});
async function getPosts() {
const { subscribe } = apiBase;
let baseUrl: string = '';
subscribe((value) => {
baseUrl = value;
})();
const req = await fetch(`${baseUrl}/timeline?pageSize=20`);
if (req.ok) {
return await req.json();
}
}
let postAModificar: Post | null = $state(null);
let mensajeError = $state('');