huge refactor. addresses #21 w/ inifinite scrolling notifications

This commit is contained in:
ari melody 2024-07-03 22:00:32 +01:00
parent f883b61659
commit 2e64f63caa
Signed by: ari
GPG key ID: CF99829C92678188
29 changed files with 887 additions and 1030 deletions

View file

@ -1,8 +1,10 @@
import { client } from '$lib/client/client.js';
import * as api from '$lib/api.js';
import { server } from '$lib/client/server.js';
import { app } from '$lib/client/app.js';
import { get, writable } from 'svelte/store';
import { parsePost } from '$lib/client/api.js';
import { parsePost } from '$lib/post.js';
export let timeline = writable([]);
export const timeline = writable([]);
let loading = false;
@ -10,9 +12,16 @@ export async function getTimeline(clean) {
if (loading) return; // no spamming!!
loading = true;
let timeline_data;
if (clean || get(timeline).length === 0) timeline_data = await get(client).getTimeline()
else timeline_data = await get(client).getTimeline(get(timeline)[get(timeline).length - 1].id);
let last_post = false;
if (!clean && get(timeline).length > 0)
last_post = get(timeline)[get(timeline).length - 1].id;
const timeline_data = await api.getTimeline(
get(server).host,
get(app).token,
"home",
last_post
);
if (!timeline_data) {
console.error(`Failed to retrieve timeline.`);
@ -24,7 +33,7 @@ export async function getTimeline(clean) {
for (let i in timeline_data) {
const post_data = timeline_data[i];
const post = await parsePost(post_data, 1, false);
const post = await parsePost(post_data, 1);
if (!post) {
if (post === null || post === undefined) {
if (post_data.id) {