2025-02-06 17:29:30 +00:00
|
|
|
<script lang="ts">
|
|
|
|
|
import {onMount} from "svelte"
|
|
|
|
|
import {page} from "$app/stores"
|
2025-02-12 00:00:14 +00:00
|
|
|
import {sortBy, sleep} from "@welshman/lib"
|
2025-10-13 20:35:02 +00:00
|
|
|
import type {MakeNonOptional} from "@welshman/lib"
|
2025-02-06 17:29:30 +00:00
|
|
|
import {COMMENT, getTagValue} from "@welshman/util"
|
2025-04-09 22:32:18 +00:00
|
|
|
import {request} from "@welshman/net"
|
|
|
|
|
import {repository} from "@welshman/app"
|
2025-02-06 17:29:30 +00:00
|
|
|
import {deriveEvents} from "@welshman/store"
|
2025-09-10 22:26:39 +00:00
|
|
|
import AltArrowLeft from "@assets/icons/alt-arrow-left.svg?dataurl"
|
|
|
|
|
import SortVertical from "@assets/icons/sort-vertical.svg?dataurl"
|
|
|
|
|
import Reply from "@assets/icons/reply-2.svg?dataurl"
|
2025-02-06 17:29:30 +00:00
|
|
|
import Icon from "@lib/components/Icon.svelte"
|
|
|
|
|
import PageBar from "@lib/components/PageBar.svelte"
|
2025-03-19 17:30:36 +00:00
|
|
|
import PageContent from "@lib/components/PageContent.svelte"
|
2025-02-06 17:29:30 +00:00
|
|
|
import Spinner from "@lib/components/Spinner.svelte"
|
|
|
|
|
import Button from "@lib/components/Button.svelte"
|
|
|
|
|
import Content from "@app/components/Content.svelte"
|
|
|
|
|
import NoteCard from "@app/components/NoteCard.svelte"
|
2025-11-13 18:36:28 +00:00
|
|
|
import SpaceMenuButton from "@app/components/SpaceMenuButton.svelte"
|
2025-02-06 18:24:31 +00:00
|
|
|
import CalendarEventActions from "@app/components/CalendarEventActions.svelte"
|
2025-02-12 00:00:14 +00:00
|
|
|
import CalendarEventHeader from "@app/components/CalendarEventHeader.svelte"
|
|
|
|
|
import CalendarEventMeta from "@app/components/CalendarEventMeta.svelte"
|
|
|
|
|
import CalendarEventDate from "@app/components/CalendarEventDate.svelte"
|
2025-02-06 18:24:31 +00:00
|
|
|
import EventReply from "@app/components/EventReply.svelte"
|
2025-08-21 22:01:31 +00:00
|
|
|
import {deriveEvent, decodeRelay} from "@app/core/state"
|
|
|
|
|
import {setChecked} from "@app/util/notifications"
|
2025-02-06 17:29:30 +00:00
|
|
|
|
2025-10-13 20:35:02 +00:00
|
|
|
const {relay, id} = $page.params as MakeNonOptional<typeof $page.params>
|
2025-02-06 17:29:30 +00:00
|
|
|
const url = decodeRelay(relay)
|
|
|
|
|
const event = deriveEvent(id)
|
|
|
|
|
const filters = [{kinds: [COMMENT], "#E": [id]}]
|
|
|
|
|
const replies = deriveEvents(repository, {filters})
|
|
|
|
|
|
|
|
|
|
const back = () => history.back()
|
|
|
|
|
|
|
|
|
|
const openReply = () => {
|
|
|
|
|
showReply = true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const closeReply = () => {
|
|
|
|
|
showReply = false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const expand = () => {
|
|
|
|
|
showAll = true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let showAll = $state(false)
|
|
|
|
|
let showReply = $state(false)
|
|
|
|
|
|
|
|
|
|
onMount(() => {
|
2025-04-11 16:27:19 +00:00
|
|
|
const controller = new AbortController()
|
|
|
|
|
|
|
|
|
|
request({relays: [url], filters, signal: controller.signal})
|
2025-02-06 17:29:30 +00:00
|
|
|
|
|
|
|
|
return () => {
|
2025-04-11 16:27:19 +00:00
|
|
|
controller.abort()
|
2025-02-06 17:29:30 +00:00
|
|
|
setChecked($page.url.pathname)
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
</script>
|
|
|
|
|
|
2025-03-19 17:30:36 +00:00
|
|
|
<PageBar>
|
|
|
|
|
{#snippet icon()}
|
|
|
|
|
<div>
|
|
|
|
|
<Button class="btn btn-neutral btn-sm flex-nowrap whitespace-nowrap" onclick={back}>
|
2025-09-10 22:26:39 +00:00
|
|
|
<Icon icon={AltArrowLeft} />
|
2025-03-19 17:30:36 +00:00
|
|
|
<span class="hidden sm:inline">Go back</span>
|
|
|
|
|
</Button>
|
|
|
|
|
</div>
|
|
|
|
|
{/snippet}
|
|
|
|
|
{#snippet title()}
|
|
|
|
|
<h1 class="text-xl">{getTagValue("title", $event?.tags || []) || ""}</h1>
|
|
|
|
|
{/snippet}
|
|
|
|
|
{#snippet action()}
|
2025-11-13 18:36:28 +00:00
|
|
|
<SpaceMenuButton {url} />
|
2025-03-19 17:30:36 +00:00
|
|
|
{/snippet}
|
|
|
|
|
</PageBar>
|
|
|
|
|
|
|
|
|
|
<PageContent class="flex flex-col gap-3 p-2 pt-4">
|
2025-02-06 17:29:30 +00:00
|
|
|
{#if $event}
|
2025-02-06 19:12:15 +00:00
|
|
|
<div class="card2 bg-alt col-3 z-feature">
|
|
|
|
|
<div class="flex items-start gap-4">
|
2025-02-12 00:00:14 +00:00
|
|
|
<CalendarEventDate event={$event} />
|
2025-03-17 16:53:14 +00:00
|
|
|
<div class="flex min-w-0 flex-grow flex-col gap-1">
|
|
|
|
|
<CalendarEventHeader event={$event} />
|
2025-04-15 18:03:27 +00:00
|
|
|
<CalendarEventMeta event={$event} {url} />
|
2025-02-06 19:12:15 +00:00
|
|
|
<div class="flex py-2 opacity-50">
|
|
|
|
|
<div class="h-px flex-grow bg-base-content opacity-25"></div>
|
|
|
|
|
</div>
|
2025-04-15 18:03:27 +00:00
|
|
|
<Content showEntire event={$event} {url} />
|
2025-02-06 19:12:15 +00:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="flex w-full flex-col justify-end sm:flex-row">
|
2025-10-06 18:23:19 +00:00
|
|
|
<CalendarEventActions showRoom {url} event={$event} />
|
2025-02-06 17:29:30 +00:00
|
|
|
</div>
|
2025-02-06 19:12:15 +00:00
|
|
|
</div>
|
2025-03-19 17:30:36 +00:00
|
|
|
{#if !showAll && $replies.length > 4}
|
|
|
|
|
<div class="flex justify-center">
|
|
|
|
|
<Button class="btn btn-link" onclick={expand}>
|
2025-09-10 22:26:39 +00:00
|
|
|
<Icon icon={SortVertical} />
|
2025-03-19 17:30:36 +00:00
|
|
|
Show all {$replies.length} replies
|
|
|
|
|
</Button>
|
|
|
|
|
</div>
|
|
|
|
|
{/if}
|
|
|
|
|
{#each sortBy(e => e.created_at, $replies).slice(0, showAll ? undefined : 4) as reply (reply.id)}
|
2025-04-15 18:03:27 +00:00
|
|
|
<NoteCard event={reply} {url} class="card2 bg-alt z-feature w-full">
|
2025-03-19 17:30:36 +00:00
|
|
|
<div class="col-3 ml-12">
|
2025-04-15 18:03:27 +00:00
|
|
|
<Content showEntire event={reply} {url} />
|
2025-03-19 17:30:36 +00:00
|
|
|
<CalendarEventActions event={reply} {url} />
|
|
|
|
|
</div>
|
|
|
|
|
</NoteCard>
|
|
|
|
|
{/each}
|
|
|
|
|
{#if showReply}
|
|
|
|
|
<EventReply {url} event={$event} onClose={closeReply} onSubmit={closeReply} />
|
|
|
|
|
{:else}
|
|
|
|
|
<div class="flex justify-end px-2 pb-2">
|
|
|
|
|
<Button class="btn btn-primary" onclick={openReply}>
|
2025-09-10 22:26:39 +00:00
|
|
|
<Icon icon={Reply} />
|
2025-03-19 17:30:36 +00:00
|
|
|
Leave comment
|
|
|
|
|
</Button>
|
|
|
|
|
</div>
|
|
|
|
|
{/if}
|
2025-02-06 17:29:30 +00:00
|
|
|
{:else}
|
|
|
|
|
{#await sleep(5000)}
|
2025-02-06 18:24:31 +00:00
|
|
|
<Spinner loading>Loading comments...</Spinner>
|
2025-02-06 17:29:30 +00:00
|
|
|
{:then}
|
2025-02-06 18:24:31 +00:00
|
|
|
<p>Failed to load comments.</p>
|
2025-02-06 17:29:30 +00:00
|
|
|
{/await}
|
|
|
|
|
{/if}
|
2025-03-19 17:30:36 +00:00
|
|
|
</PageContent>
|