2024-06-17 21:17:27 +01:00
|
|
|
<script>
|
2024-07-02 19:38:20 +01:00
|
|
|
import { page } from '$app/stores';
|
2024-07-07 14:33:28 +01:00
|
|
|
import { account } from '$lib/stores/account.js';
|
2024-07-02 19:38:20 +01:00
|
|
|
import { timeline, getTimeline } from '$lib/timeline.js';
|
2025-07-15 15:08:37 +01:00
|
|
|
import { app_name } from '$lib/config.js';
|
2025-07-13 18:49:49 +01:00
|
|
|
import Lang from '$lib/lang';
|
2024-07-01 03:41:02 +01:00
|
|
|
|
|
|
|
import LoginForm from '$lib/ui/LoginForm.svelte';
|
2024-07-07 12:22:29 +01:00
|
|
|
import Button from '$lib/ui/Button.svelte';
|
|
|
|
import Post from '$lib/ui/post/Post.svelte';
|
2025-07-14 18:16:40 +01:00
|
|
|
import PageHeader from '../lib/ui/core/PageHeader.svelte';
|
2024-07-02 19:38:20 +01:00
|
|
|
|
2025-07-15 00:02:12 +01:00
|
|
|
const lang = Lang();
|
2025-07-13 18:35:26 +01:00
|
|
|
|
2025-07-15 15:08:37 +01:00
|
|
|
// TODO: refactor to enum when moving to TS
|
|
|
|
let timelineType = localStorage.getItem(app_name + '_selected_timeline') || "home";
|
|
|
|
|
|
|
|
$: {
|
|
|
|
// awful hack to update timeline fresh
|
|
|
|
// when timelineType is updated
|
|
|
|
//
|
|
|
|
// TODO: migrate to $effect when migrating to svelte 5
|
|
|
|
timelineType = timelineType
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-07-07 14:33:28 +01:00
|
|
|
account.subscribe(account => {
|
2025-07-15 15:08:37 +01:00
|
|
|
if (account) getCurrentTimeline();
|
2024-07-02 20:21:34 +01:00
|
|
|
});
|
2024-07-07 12:22:29 +01:00
|
|
|
|
2025-07-13 20:44:54 +01:00
|
|
|
document.addEventListener('scroll', () => {
|
2024-07-07 14:58:59 +01:00
|
|
|
if ($account && $page.url.pathname !== "/") return;
|
2024-07-02 19:38:20 +01:00
|
|
|
if (window.innerHeight + window.scrollY >= document.body.offsetHeight - 2048) {
|
2025-07-15 15:08:37 +01:00
|
|
|
getCurrentTimeline();
|
2024-07-02 19:38:20 +01:00
|
|
|
}
|
|
|
|
});
|
2024-06-17 21:17:27 +01:00
|
|
|
</script>
|
|
|
|
|
2024-07-07 14:33:28 +01:00
|
|
|
{#if $account}
|
2025-07-15 15:08:37 +01:00
|
|
|
<PageHeader title={lang.string(`timeline.${timelineType}`)}>
|
|
|
|
<Button centered
|
|
|
|
active={(timelineType == "home")}
|
|
|
|
on:click={() => timelineType = "home"}>
|
|
|
|
{lang.string('timeline.home')}
|
|
|
|
</Button>
|
|
|
|
<Button centered
|
|
|
|
active={(timelineType == "local")}
|
|
|
|
on:click={() => timelineType = "local"}>
|
|
|
|
{lang.string('timeline.local')}
|
|
|
|
</Button>
|
|
|
|
<Button centered
|
|
|
|
active={(timelineType == "federated")}
|
|
|
|
on:click={() => timelineType = "federated"}>
|
|
|
|
{lang.string('timeline.federated')}
|
|
|
|
</Button>
|
2025-07-14 18:16:40 +01:00
|
|
|
</PageHeader>
|
2024-07-07 12:22:29 +01:00
|
|
|
|
|
|
|
<div id="feed" role="feed">
|
|
|
|
{#if $timeline.length <= 0}
|
|
|
|
<div class="loading throb">
|
2025-07-13 18:35:26 +01:00
|
|
|
<span>{lang.string('timeline.fetching')}</span>
|
2024-07-07 12:22:29 +01:00
|
|
|
</div>
|
|
|
|
{/if}
|
|
|
|
{#each $timeline as post}
|
|
|
|
<Post post_data={post} />
|
|
|
|
{/each}
|
|
|
|
</div>
|
2024-06-29 23:10:29 +01:00
|
|
|
{:else}
|
2024-07-01 03:41:02 +01:00
|
|
|
<LoginForm />
|
2024-06-29 17:27:46 +01:00
|
|
|
{/if}
|
2024-06-17 21:17:27 +01:00
|
|
|
|
|
|
|
<style>
|
2024-07-07 12:22:29 +01:00
|
|
|
#feed {
|
|
|
|
margin-bottom: 20vh;
|
|
|
|
}
|
|
|
|
|
|
|
|
.loading {
|
|
|
|
width: 100%;
|
|
|
|
height: 80vh;
|
|
|
|
display: flex;
|
|
|
|
justify-content: center;
|
|
|
|
align-items: center;
|
|
|
|
font-size: 2em;
|
|
|
|
font-weight: bold;
|
2024-06-29 15:24:33 +01:00
|
|
|
}
|
2024-06-17 21:17:27 +01:00
|
|
|
</style>
|