campfire/src/routes/+page.svelte

88 lines
2 KiB
Svelte
Raw Normal View History

<script>
import { page } from '$app/stores';
import { account } from '$lib/stores/account.js';
import { timeline, getTimeline } from '$lib/timeline.js';
2025-07-13 18:49:49 +01:00
import Lang from '$lib/lang';
import LoginForm from '$lib/ui/LoginForm.svelte';
import Button from '$lib/ui/Button.svelte';
import Post from '$lib/ui/post/Post.svelte';
const lang = Lang('en_GB');
account.subscribe(account => {
if (account) getTimeline();
2024-07-02 20:21:34 +01:00
});
document.addEventListener("scroll", () => {
if ($account && $page.url.pathname !== "/") return;
if (window.innerHeight + window.scrollY >= document.body.offsetHeight - 2048) {
getTimeline();
}
});
</script>
{#if $account}
<header>
<h1>{lang.string('timeline.home')}</h1>
<nav>
<Button centered active>{lang.string('timeline.home')}</Button>
<Button centered disabled>{lang.string('timeline.local')}</Button>
<Button centered disabled>{lang.string('timeline.federated')}</Button>
</nav>
</header>
<div id="feed" role="feed">
{#if $timeline.length <= 0}
<div class="loading throb">
<span>{lang.string('timeline.fetching')}</span>
</div>
{/if}
{#each $timeline as post}
<Post post_data={post} />
{/each}
</div>
{:else}
<LoginForm />
2024-06-29 17:27:46 +01:00
{/if}
<style>
2024-06-29 17:27:46 +01:00
header {
width: 100%;
height: 64px;
margin: 16px 0;
padding: 0 8px;
display: flex;
flex-direction: row;
2025-07-10 18:11:49 +01:00
user-select: none;
box-sizing: border-box;
}
2024-06-29 17:27:46 +01:00
header h1 {
font-size: 1.5em;
}
nav {
margin-left: auto;
display: flex;
flex-direction: row;
2025-07-10 22:32:54 +01:00
align-items: center;
gap: 8px;
}
#feed {
margin-bottom: 20vh;
}
.loading {
width: 100%;
height: 80vh;
display: flex;
justify-content: center;
align-items: center;
font-size: 2em;
font-weight: bold;
}
</style>