refactor: use Link HTTP header for pagination

This commit is contained in:
mae taylor 2025-07-15 16:34:23 +01:00
parent 99def58c8b
commit 3b8ca902f1
Signed by: mae
GPG key ID: 3C80D76BA7A3B9BD
2 changed files with 74 additions and 32 deletions

View file

@ -10,14 +10,14 @@ export const timeline = writable([]);
const lang = Lang();
let loading = false;
let last_post = false;
export async function getTimeline(timelineType = "home", clean, localOnly = false, remoteOnly = false) {
if (loading) return; // no spamming!!
loading = true;
let last_post = false;
if (!clean && get(timeline).length > 0)
last_post = get(timeline)[get(timeline).length - 1].id;
// if (!clean && get(timeline).length > 0)
// last_post = get(timeline)[get(timeline).length - 1].id;
let timeline_data;
switch(timelineType) {
@ -25,7 +25,7 @@ export async function getTimeline(timelineType = "home", clean, localOnly = fals
timeline_data = await api.getFavourites(
get(server).host,
get(app).token,
last_post,
last_post
)
break;
@ -47,10 +47,15 @@ export async function getTimeline(timelineType = "home", clean, localOnly = fals
return;
}
if (clean) timeline.set([]);
if (clean) {
timeline.set([]);
last_post = false;
} else {
last_post = timeline_data.next.url.searchParams.get("max_id")
}
for (let i in timeline_data) {
const post_data = timeline_data[i];
for (let i in timeline_data.data) {
const post_data = timeline_data.data[i];
const post = await parsePost(post_data, 1);
if (!post) {
if (post === null || post === undefined) {