flotilla/src/routes/spaces/[nrelay]/threads/+page.svelte

71 lines
2.1 KiB
Svelte
Raw Normal View History

2024-09-23 20:10:15 +00:00
<script lang="ts">
2024-10-09 23:11:23 +00:00
import {onMount} from 'svelte'
2024-09-23 20:10:15 +00:00
import {page} from "$app/stores"
2024-09-23 20:58:01 +00:00
import {sortBy} from "@welshman/lib"
2024-10-09 23:11:23 +00:00
import {createScroller} from '@lib/html'
2024-09-23 20:10:15 +00:00
import Icon from "@lib/components/Icon.svelte"
import Button from "@lib/components/Button.svelte"
2024-10-09 23:11:23 +00:00
import PageBar from "@lib/components/PageBar.svelte"
2024-09-23 20:10:15 +00:00
import Spinner from "@lib/components/Spinner.svelte"
import ThreadItem from "@app/components/ThreadItem.svelte"
2024-09-23 20:10:15 +00:00
import ThreadCreate from "@app/components/ThreadCreate.svelte"
import {pushModal} from "@app/modal"
import {threadsByUrl, decodeNRelay} from "@app/state"
const url = decodeNRelay($page.params.nrelay)
const createThread = () => pushModal(ThreadCreate, {url})
2024-10-09 23:11:23 +00:00
let limit = 10
2024-09-23 20:10:15 +00:00
let loading = true
2024-10-09 23:11:23 +00:00
let element: Element
2024-09-23 20:10:15 +00:00
$: threads = sortBy(thread => -thread.root.created_at, $threadsByUrl.get(url) || [])
2024-10-09 23:11:23 +00:00
onMount(() => {
const scroller = createScroller({
element: element.closest('.max-h-screen')!,
onScroll: async () => {
limit += 10
}
})
return () => scroller.stop()
})
2024-09-23 20:10:15 +00:00
setTimeout(() => {
loading = false
}, 3000)
</script>
2024-10-09 23:11:23 +00:00
<div class="relative flex h-screen flex-col" bind:this={element}>
<PageBar>
<div slot="icon" class="center">
<Icon icon="notes-minimalistic" />
2024-09-23 20:10:15 +00:00
</div>
2024-10-09 23:11:23 +00:00
<strong slot="title">Threads</strong>
</PageBar>
2024-09-23 20:58:01 +00:00
<div class="flex flex-grow flex-col gap-2 overflow-auto p-2">
2024-10-09 23:11:23 +00:00
{#each threads.slice(0, 10) as { root, replies } (root.id)}
<ThreadItem {root} {replies} />
2024-09-23 20:10:15 +00:00
{/each}
<p class="flex h-10 items-center justify-center py-20">
<Spinner {loading}>
{#if loading}
Looking for threads...
{:else if threads.length === 0}
No threads found.
{/if}
</Spinner>
</p>
</div>
2024-09-23 20:58:01 +00:00
<Button
2024-10-09 23:11:23 +00:00
class="tooltip tooltip-left fixed bottom-16 sm:bottom-4 right-2 sm:right-4 p-1 z-feature"
2024-09-23 20:58:01 +00:00
data-tip="Create an Event"
on:click={createThread}>
<div class="btn btn-circle btn-primary flex h-12 w-12 items-center justify-center">
2024-09-24 21:12:38 +00:00
<Icon icon="notes-minimalistic" />
2024-09-23 20:10:15 +00:00
</div>
</Button>
</div>