diff --git a/src/lib/account.js b/src/lib/account.js index 43d1ac1..3e08748 100644 --- a/src/lib/account.js +++ b/src/lib/account.js @@ -41,7 +41,7 @@ export function parseAccount(data) { else account.host = get(server).host; - account.fqn = data.fqn || account.username + "@" + account.host; + account.fqn = data.fqn || account.username + account.host; account.mention = "@" + account.username; if (account.host != get(server).host) diff --git a/src/lib/api.js b/src/lib/api.js index 7401f0f..812ddd0 100644 --- a/src/lib/api.js +++ b/src/lib/api.js @@ -285,17 +285,13 @@ export async function getTimeline(host, token, timeline, max_id, local_only, rem headers: { "Authorization": token ? `Bearer ${token}` : null } }) - let res = { - data: await data.json() - } + let links = _parseLinkHeader(data.headers.get("Link")); - if(data.headers.has("Link")) { - let links = _parseLinkHeader(data.headers.get("Link")); - res["prev"] = links.find(f=>f.rel=="prev"); - res["next"] = links.find(f=>f.rel=="next"); - } - - return res; + return { + data: await data.json(), + prev: links.find(f=>f.rel=="prev"), + next: links.find(f=>f.rel=="next") + }; } /** @@ -316,18 +312,14 @@ export async function getFavourites(host, token, max_id) { method: 'GET', headers: { "Authorization": token ? `Bearer ${token}` : null } }) - - let res = { - data: await data.json() - } - if(data.headers.has("Link")) { - let links = _parseLinkHeader(data.headers.get("Link")); - res["prev"] = links.find(f=>f.rel=="prev"); - res["next"] = links.find(f=>f.rel=="next"); - } + let links = _parseLinkHeader(data.headers.get("Link")); - return res; + return { + data: await data.json(), + prev: links.find(f=>f.rel=="prev"), + next: links.find(f=>f.rel=="next") + }; } /** diff --git a/src/lib/timeline.js b/src/lib/timeline.js index 5e86f5f..68aa2b2 100644 --- a/src/lib/timeline.js +++ b/src/lib/timeline.js @@ -10,15 +10,12 @@ export const timeline = writable([]); const lang = Lang(); let loading = false; -let last_post = false; // last post marker, used for fetching next sequence of posts -let at_end = false; // at end of timeline, no next param to paginate +let last_post = false; export async function getTimeline(timelineType = "home", clean, localOnly = false, remoteOnly = false) { if (loading) return; // no spamming!! loading = true; - if(at_end) return; - if(clean) { timeline.set([]); last_post = false; @@ -52,12 +49,9 @@ export async function getTimeline(timelineType = "home", clean, localOnly = fals return; } - if (!clean && timeline_data.next) { + if (!clean) { last_post = timeline_data.next.url.searchParams.get("max_id") - } else if(!timeline_data.next) { - console.log(timeline_data) - at_end = true; - } + } for (let i in timeline_data.data) { const post_data = timeline_data.data[i]; @@ -77,9 +71,3 @@ export async function getTimeline(timelineType = "home", clean, localOnly = fals } loading = false; } - -export function clearTimeline() { - timeline.set([]); - last_post = false; - at_end = false; -} \ No newline at end of file diff --git a/src/lib/ui/timeline/Timeline.svelte b/src/lib/ui/timeline/Timeline.svelte deleted file mode 100644 index 1053fef..0000000 --- a/src/lib/ui/timeline/Timeline.svelte +++ /dev/null @@ -1,78 +0,0 @@ - -
- {#if $timeline.length <= 0} -
- {lang.string('timeline.fetching')} -
- {/if} - {#each $timeline as post} - - {/each} -
- - - diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index 5cae86d..3375ab4 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -9,7 +9,6 @@ import Button from '$lib/ui/Button.svelte'; import Post from '$lib/ui/post/Post.svelte'; import PageHeader from '../lib/ui/core/PageHeader.svelte'; - import Timeline from '../lib/ui/timeline/Timeline.svelte'; const lang = Lang(); @@ -25,7 +24,40 @@ // set in localStorage localStorage.setItem(app_name + '_selected_timeline', timelineType); + + // erase the timeline here so the ui reacts instantly + // mae: i could write an awesome undertale reference here + timeline.set([]); + + getCurrentTimeline() } + + function getCurrentTimeline(clean = false) { + switch(timelineType) { + case "home": + getTimeline("home", clean); + break; + + case "local": + getTimeline("public", clean, true) + break; + + case "federated": + getTimeline("public", clean, false, true) + break; + } + } + + account.subscribe(account => { + if (account) getCurrentTimeline(); + }); + + document.addEventListener('scroll', () => { + if ($account && $page.url.pathname !== "/") return; + if (window.innerHeight + window.scrollY >= document.body.offsetHeight - 2048) { + getCurrentTimeline(); + } + }); {#if $account} @@ -47,12 +79,24 @@ - +
+ {#if $timeline.length <= 0} +
+ {lang.string('timeline.fetching')} +
+ {/if} + {#each $timeline as post} + + {/each} +
{:else} {/if}