forked from blisstown/campfire
finish sk restructure, a11y and optimisations
This commit is contained in:
parent
9ef27fd2a2
commit
3ae05b3f9f
61 changed files with 416 additions and 429 deletions
43
src/lib/timeline.js
Normal file
43
src/lib/timeline.js
Normal file
|
@ -0,0 +1,43 @@
|
|||
import { Client } from '$lib/client/client.js';
|
||||
import { get, writable } from 'svelte/store';
|
||||
import { parsePost } from '$lib/client/api.js';
|
||||
|
||||
export let posts = writable([]);
|
||||
|
||||
let client = get(Client.get());
|
||||
let loading = false;
|
||||
|
||||
export async function getTimeline(clean) {
|
||||
if (loading) return; // no spamming!!
|
||||
loading = true;
|
||||
|
||||
let timeline_data;
|
||||
if (get(posts).length === 0) timeline_data = await client.getTimeline()
|
||||
else timeline_data = await client.getTimeline(get(posts)[get(posts).length - 1].id);
|
||||
|
||||
if (!timeline_data) {
|
||||
console.error(`Failed to retrieve timeline.`);
|
||||
loading = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if (clean) posts.set([]);
|
||||
|
||||
for (let i in timeline_data) {
|
||||
const post_data = timeline_data[i];
|
||||
const post = await parsePost(post_data, 1, false);
|
||||
if (!post) {
|
||||
if (post === null || post === undefined) {
|
||||
if (post_data.id) {
|
||||
console.warn("Failed to parse post #" + post_data.id);
|
||||
} else {
|
||||
console.warn("Failed to parse post:");
|
||||
console.warn(post_data);
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
posts.update(current => [...current, post]);
|
||||
}
|
||||
loading = false;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue