mirror of
https://github.com/emailerfacu-spec/minix-front.git
synced 2026-04-13 15:10:43 -03:00
add infinite scroll
This commit is contained in:
@@ -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();
|
||||
}
|
||||
Reference in New Issue
Block a user