2024-09-11 22:21:25 +00:00
|
|
|
<script lang="ts">
|
|
|
|
|
import {page} from "$app/stores"
|
2024-09-23 20:58:01 +00:00
|
|
|
import {sortBy, last} from "@welshman/lib"
|
|
|
|
|
import type {TrustedEvent} from "@welshman/util"
|
2024-09-20 18:00:41 +00:00
|
|
|
import {formatTimestampAsDate} from "@welshman/app"
|
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-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"
|
|
|
|
|
import {pushModal} from "@app/modal"
|
|
|
|
|
import {eventsByUrl, decodeNRelay} from "@app/state"
|
|
|
|
|
|
|
|
|
|
const url = decodeNRelay($page.params.nrelay)
|
|
|
|
|
|
2024-09-20 18:00:41 +00:00
|
|
|
const createEvent = () => pushModal(EventCreate, {url})
|
2024-09-11 22:21:25 +00:00
|
|
|
|
2024-09-20 18:00:41 +00:00
|
|
|
const getStart = (event: TrustedEvent) =>
|
2024-09-23 20:58:01 +00:00
|
|
|
parseInt(event.tags.find(t => t[0] === "start")?.[1] || "0")
|
2024-09-11 22:21:25 +00:00
|
|
|
|
2024-09-20 18:00:41 +00:00
|
|
|
let loading = true
|
|
|
|
|
|
|
|
|
|
type Item = {
|
|
|
|
|
event: TrustedEvent
|
|
|
|
|
dateDisplay?: string
|
2024-09-11 22:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2024-09-23 20:58:01 +00:00
|
|
|
$: items = sortBy(getStart, $eventsByUrl.get(url) || []).reduce<Item[]>((r, event) => {
|
|
|
|
|
const prevDateDisplay =
|
|
|
|
|
r.length > 0 ? formatTimestampAsDate(getStart(last(r).event)) : undefined
|
|
|
|
|
const newDateDisplay = formatTimestampAsDate(getStart(event))
|
|
|
|
|
const dateDisplay = prevDateDisplay === newDateDisplay ? undefined : newDateDisplay
|
2024-09-11 22:21:25 +00:00
|
|
|
|
2024-09-23 20:58:01 +00:00
|
|
|
return [...r, {event, dateDisplay}]
|
|
|
|
|
}, [])
|
2024-09-11 22:21:25 +00:00
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
loading = false
|
|
|
|
|
}, 3000)
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<div class="relative flex h-screen flex-col">
|
2024-10-09 23:11:23 +00:00
|
|
|
<PageBar>
|
|
|
|
|
<div slot="icon" class="center">
|
|
|
|
|
<Icon icon="calendar-minimalistic" />
|
2024-09-11 22:21:25 +00:00
|
|
|
</div>
|
2024-10-09 23:11:23 +00:00
|
|
|
<strong slot="title">Calendar</strong>
|
|
|
|
|
</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}
|
2024-09-24 17:56:42 +00:00
|
|
|
<EventItem {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-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={createEvent}>
|
|
|
|
|
<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>
|