flotilla/src/app/components/CalendarEventHeader.svelte

39 lines
1.3 KiB
Svelte
Raw Normal View History

<script lang="ts">
2026-07-28 16:16:26 +00:00
import {formatTimestamp, formatTimestampAsDate, formatTimestampAsTime} from "@welshman/lib"
import type {TrustedEvent} from "@welshman/util"
2026-07-28 16:16:26 +00:00
import {tagSpec, tagValue} from "@welshman/util"
import {TimeEvent} from "@welshman/domain"
2025-09-10 22:26:39 +00:00
import ClockCircle from "@assets/icons/clock-circle.svg?dataurl"
import Icon from "@lib/components/Icon.svelte"
2026-07-28 16:16:26 +00:00
import {reader} from "@app/core"
type Props = {
event: TrustedEvent
}
const {event}: Props = $props()
2026-07-28 16:16:26 +00:00
const timeEvent = reader(TimeEvent)(event)
// NIP-52 settled on `title`, but events from before that still carry `name`.
const title = $derived(timeEvent.title() ?? tagValue(tagSpec("name"), event.tags))
const start = timeEvent.start()
const end = timeEvent.end()
</script>
<div class="flex flex-col justify-between gap-1">
2026-07-28 16:16:26 +00:00
<p class="text-lg">{title}</p>
{#if start && end}
{@const isSingleDay = formatTimestampAsDate(start) === formatTimestampAsDate(end)}
<div class="flex flex-wrap gap-2 text-xs">
<div class="flex items-center gap-2">
<Icon icon={ClockCircle} size={4} />
{formatTimestampAsDate(start)}
</div>
2025-10-06 18:23:19 +00:00
{formatTimestampAsTime(start)} — {isSingleDay
? formatTimestampAsTime(end)
: formatTimestamp(end)}
</div>
{/if}
</div>