mirror of
https://github.com/emailerfacu-spec/minix-front.git
synced 2026-04-01 13:10:44 -03:00
chore: movi el getPosts a hooks/ y le agrege un header
This commit is contained in:
17
src/lib/hooks/getPosts.ts
Normal file
17
src/lib/hooks/getPosts.ts
Normal 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();
|
||||
}
|
||||
}
|
||||
@@ -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('');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user