flotilla/src/app/components/CalendarEventItem.svelte

48 lines
2 KiB
Svelte
Raw Normal View History

2024-09-20 18:00:41 +00:00
<script lang="ts">
import {fromPairs} from "@welshman/lib"
2025-02-05 23:05:58 +00:00
import {formatTimestamp, formatTimestampAsDate, formatTimestampAsTime} from "@welshman/app"
2025-02-05 21:02:51 +00:00
import {preventDefault} from "@lib/html"
2024-09-20 18:00:41 +00:00
import Icon from "@lib/components/Icon.svelte"
2025-02-06 17:29:30 +00:00
import Link from "@lib/components/Link.svelte"
2025-02-05 21:02:51 +00:00
import Button from "@lib/components/Button.svelte"
import Content from "@app/components/Content.svelte"
2025-02-06 17:29:30 +00:00
import CalendarEventActions from "@app/components/CalendarEventActions.svelte"
2025-02-05 21:02:51 +00:00
import ProfileName from "@app/components/ProfileName.svelte"
import ProfileDetail from "@app/components/ProfileDetail.svelte"
2025-02-06 17:29:30 +00:00
import {makeCalendarPath} from "@app/routes"
2025-02-05 21:02:51 +00:00
import {pushModal} from "@app/modal"
2024-09-20 18:00:41 +00:00
2025-02-05 21:02:51 +00:00
const {url, event} = $props()
2024-09-20 18:00:41 +00:00
const meta = $derived(fromPairs(event.tags) as Record<string, string>)
const end = $derived(parseInt(meta.end))
const start = $derived(parseInt(meta.start))
const startDateDisplay = $derived(formatTimestampAsDate(start))
const endDateDisplay = $derived(formatTimestampAsDate(end))
const isSingleDay = $derived(startDateDisplay === endDateDisplay)
2025-02-05 21:02:51 +00:00
const openProfile = () => pushModal(ProfileDetail, {pubkey: event.pubkey})
2024-09-20 18:00:41 +00:00
</script>
2025-02-06 17:29:30 +00:00
<Link class="col-2 card2 bg-alt w-full cursor-pointer" href={makeCalendarPath(url, event.id)}>
2025-02-05 21:02:51 +00:00
<div class="flex items-center justify-between gap-2">
<span>{meta.title || meta.name}</span>
<div class="flex items-center gap-2 text-sm">
<Icon icon="clock-circle" size={4} />
{formatTimestampAsTime(start)} — {isSingleDay
? formatTimestampAsTime(end)
: formatTimestamp(end)}
</div>
</div>
<Content {event} />
<div class="flex w-full flex-col items-end justify-between gap-2 sm:flex-row">
<span class="whitespace-nowrap py-1 text-sm opacity-75">
Posted by
<Button onclick={preventDefault(openProfile)} class="link-content">
@<ProfileName pubkey={event.pubkey} />
</Button>
</span>
2025-02-06 17:29:30 +00:00
<CalendarEventActions {url} {event} />
2024-09-20 18:00:41 +00:00
</div>
2025-02-06 17:29:30 +00:00
</Link>