add infinite scroll

This commit is contained in:
Fran
2026-01-15 19:17:28 -03:00
parent 3a5994d13a
commit 6d08a0985b
4 changed files with 138 additions and 61 deletions

View File

@@ -1,17 +1,21 @@
import { apiBase } from "@/stores/url";
import { sesionStore } from "@/stores/usuario";
import { get } from "svelte/store";
import type { Post } from '../../types';
import { PAGE_SIZE } from '../stores/posts';
export async function getPosts() {
export async function getPosts(page: number = 1): Promise<Post[]> {
const token = get(sesionStore)?.accessToken;
const headers: HeadersInit = {};
if (token) headers.Authorization = `Bearer ${token}`;
const req = await fetch(`${get(apiBase)}/timeline?pageSize=20`,{
headers: {
Authorization: `Bearer ${get(sesionStore)?.accessToken}`
const res = await fetch(
`${get(apiBase)}/timeline?page=${page}&pageSize=${PAGE_SIZE}`,
{ headers }
);
}
});
if (req.ok) {
return await req.json();
}
}
if (!res.ok) throw new Error('Error cargando posts');
return res.json();
}