2024-09-11 22:21:25 +00:00
|
|
|
<script lang="ts">
|
2024-11-14 18:53:13 +00:00
|
|
|
import {onMount, onDestroy} from "svelte"
|
2024-09-11 22:21:25 +00:00
|
|
|
import {page} from "$app/stores"
|
2025-02-05 23:05:58 +00:00
|
|
|
import {sortBy, now, int, MONTH, last} from "@welshman/lib"
|
2024-09-23 20:58:01 +00:00
|
|
|
import type {TrustedEvent} from "@welshman/util"
|
2025-02-05 23:05:58 +00:00
|
|
|
import {EVENT_DATE, EVENT_TIME, getTagValue} from "@welshman/util"
|
2024-10-11 00:15:20 +00:00
|
|
|
import {subscribe, formatTimestampAsDate} from "@welshman/app"
|
2025-02-05 23:05:58 +00:00
|
|
|
import {timeHashesForFilter} from "@lib/util"
|
2024-09-11 22:21:25 +00:00
|
|
|
import Icon from "@lib/components/Icon.svelte"
|
|
|
|
|
import Button from "@lib/components/Button.svelte"
|
|
|
|
|
import Spinner from "@lib/components/Spinner.svelte"
|
2024-10-09 23:11:23 +00:00
|
|
|
import PageBar from "@lib/components/PageBar.svelte"
|
2024-09-20 18:00:41 +00:00
|
|
|
import Divider from "@lib/components/Divider.svelte"
|
2024-11-15 22:03:54 +00:00
|
|
|
import MenuSpaceButton from "@app/components/MenuSpaceButton.svelte"
|
2024-09-24 17:56:42 +00:00
|
|
|
import EventItem from "@app/components/EventItem.svelte"
|
2024-09-11 22:21:25 +00:00
|
|
|
import EventCreate from "@app/components/EventCreate.svelte"
|
2024-11-15 22:03:54 +00:00
|
|
|
import {pushModal} from "@app/modal"
|
2024-12-11 00:38:22 +00:00
|
|
|
import {deriveEventsForUrl, decodeRelay} from "@app/state"
|
|
|
|
|
import {pullConservatively} from "@app/requests"
|
2024-11-14 18:53:13 +00:00
|
|
|
import {setChecked} from "@app/notifications"
|
2024-09-11 22:21:25 +00:00
|
|
|
|
2024-10-21 17:30:12 +00:00
|
|
|
const url = decodeRelay($page.params.relay)
|
2024-10-11 00:09:01 +00:00
|
|
|
const kinds = [EVENT_DATE, EVENT_TIME]
|
2024-10-24 22:48:45 +00:00
|
|
|
const events = deriveEventsForUrl(url, [{kinds}])
|
2024-09-11 22:21:25 +00:00
|
|
|
|
2024-09-20 18:00:41 +00:00
|
|
|
const createEvent = () => pushModal(EventCreate, {url})
|
2024-09-11 22:21:25 +00:00
|
|
|
|
2025-02-05 23:05:58 +00:00
|
|
|
const getEnd = (event: TrustedEvent) => parseInt(getTagValue("end", event.tags) || "")
|
2024-10-18 16:53:35 +00:00
|
|
|
|
2025-02-05 23:05:58 +00:00
|
|
|
const getStart = (event: TrustedEvent) => parseInt(getTagValue("start", event.tags) || "")
|
2024-09-11 22:21:25 +00:00
|
|
|
|
2024-10-21 21:35:12 +00:00
|
|
|
const limit = 5
|
2025-02-04 00:37:14 +00:00
|
|
|
let loading = $state(true)
|
2024-09-20 18:00:41 +00:00
|
|
|
|
|
|
|
|
type Item = {
|
|
|
|
|
event: TrustedEvent
|
|
|
|
|
dateDisplay?: string
|
2024-09-11 22:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2025-02-04 01:21:46 +00:00
|
|
|
const items = $derived(
|
2025-02-05 23:05:58 +00:00
|
|
|
sortBy(e => getStart(e), $events)
|
2025-02-04 00:37:14 +00:00
|
|
|
.reduce<Item[]>((r, event) => {
|
|
|
|
|
const end = getEnd(event)
|
|
|
|
|
const start = getStart(event)
|
2024-10-18 16:53:35 +00:00
|
|
|
|
2025-02-04 00:37:14 +00:00
|
|
|
if (isNaN(start) || isNaN(end)) return r
|
2024-10-18 16:53:35 +00:00
|
|
|
|
2025-02-04 00:37:14 +00:00
|
|
|
const prevDateDisplay =
|
|
|
|
|
r.length > 0 ? formatTimestampAsDate(getStart(last(r).event)) : undefined
|
|
|
|
|
const newDateDisplay = formatTimestampAsDate(start)
|
|
|
|
|
const dateDisplay = prevDateDisplay === newDateDisplay ? undefined : newDateDisplay
|
2024-09-11 22:21:25 +00:00
|
|
|
|
2025-02-04 00:37:14 +00:00
|
|
|
return [...r, {event, dateDisplay}]
|
|
|
|
|
}, [])
|
|
|
|
|
.slice(0, limit),
|
|
|
|
|
)
|
2024-09-11 22:21:25 +00:00
|
|
|
|
2024-10-11 00:09:01 +00:00
|
|
|
onMount(() => {
|
2025-02-05 23:05:58 +00:00
|
|
|
const sub = subscribe({filters: [{kinds, since: now()}]})
|
|
|
|
|
const hashes = timeHashesForFilter(now() - int(3, MONTH), now() + int(3, MONTH))
|
2024-10-11 00:09:01 +00:00
|
|
|
|
2025-02-05 23:05:58 +00:00
|
|
|
pullConservatively({filters: [{kinds, "#T": hashes}], relays: [url]})
|
2024-10-11 00:09:01 +00:00
|
|
|
|
|
|
|
|
return () => sub.close()
|
|
|
|
|
})
|
|
|
|
|
|
2024-11-14 18:53:13 +00:00
|
|
|
onDestroy(() => {
|
|
|
|
|
setChecked($page.url.pathname)
|
|
|
|
|
})
|
|
|
|
|
|
2024-09-11 22:21:25 +00:00
|
|
|
setTimeout(() => {
|
|
|
|
|
loading = false
|
2024-10-24 18:52:02 +00:00
|
|
|
}, 5000)
|
2024-09-11 22:21:25 +00:00
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<div class="relative flex h-screen flex-col">
|
2024-10-09 23:11:23 +00:00
|
|
|
<PageBar>
|
2025-02-04 00:37:14 +00:00
|
|
|
{#snippet icon()}
|
|
|
|
|
<div class="center">
|
|
|
|
|
<Icon icon="calendar-minimalistic" />
|
|
|
|
|
</div>
|
|
|
|
|
{/snippet}
|
|
|
|
|
{#snippet title()}
|
|
|
|
|
<strong>Calendar</strong>
|
|
|
|
|
{/snippet}
|
|
|
|
|
{#snippet action()}
|
|
|
|
|
<div class="md:hidden">
|
|
|
|
|
<MenuSpaceButton {url} />
|
|
|
|
|
</div>
|
|
|
|
|
{/snippet}
|
2024-10-09 23:11:23 +00:00
|
|
|
</PageBar>
|
2024-09-23 20:58:01 +00:00
|
|
|
<div class="flex flex-grow flex-col gap-2 overflow-auto p-2">
|
|
|
|
|
{#each items as { event, dateDisplay }, i (event.id)}
|
2024-09-11 22:21:25 +00:00
|
|
|
{#if dateDisplay}
|
2024-09-20 18:00:41 +00:00
|
|
|
<Divider>{dateDisplay}</Divider>
|
2024-09-11 22:21:25 +00:00
|
|
|
{/if}
|
2025-02-05 21:02:51 +00:00
|
|
|
<EventItem {url} {event} />
|
2024-09-11 22:21:25 +00:00
|
|
|
{/each}
|
|
|
|
|
<p class="flex h-10 items-center justify-center py-20">
|
|
|
|
|
<Spinner {loading}>
|
|
|
|
|
{#if loading}
|
|
|
|
|
Looking for events...
|
2024-09-20 18:00:41 +00:00
|
|
|
{:else if items.length === 0}
|
2024-09-11 22:21:25 +00:00
|
|
|
No events found.
|
|
|
|
|
{/if}
|
|
|
|
|
</Spinner>
|
|
|
|
|
</p>
|
|
|
|
|
</div>
|
2024-09-23 20:58:01 +00:00
|
|
|
<Button
|
2024-10-18 16:53:35 +00:00
|
|
|
class="tooltip tooltip-left fixed bottom-16 right-2 z-feature p-1 md:bottom-4 md:right-4"
|
2024-09-23 20:58:01 +00:00
|
|
|
data-tip="Create an Event"
|
2025-02-04 01:21:46 +00:00
|
|
|
onclick={createEvent}>
|
2024-09-23 20:58:01 +00:00
|
|
|
<div class="btn btn-circle btn-primary flex h-12 w-12 items-center justify-center">
|
2024-09-23 20:10:15 +00:00
|
|
|
<Icon icon="calendar-add" />
|
2024-09-11 22:21:25 +00:00
|
|
|
</div>
|
|
|
|
|
</Button>
|
|
|
|
|
</div>
|