2026-02-03 19:00:13 +00:00
|
|
|
<script lang="ts">
|
|
|
|
|
import {onMount} from "svelte"
|
|
|
|
|
import {page} from "$app/stores"
|
|
|
|
|
import {sleep} from "@welshman/lib"
|
|
|
|
|
import type {MakeNonOptional} from "@welshman/lib"
|
|
|
|
|
import {COMMENT, getTagValue} from "@welshman/util"
|
|
|
|
|
import {repository} from "@welshman/app"
|
|
|
|
|
import {request} from "@welshman/net"
|
|
|
|
|
import {deriveEventsById, deriveEventsAsc} from "@welshman/store"
|
|
|
|
|
import SortVertical from "@assets/icons/sort-vertical.svg?dataurl"
|
|
|
|
|
import Reply from "@assets/icons/reply-2.svg?dataurl"
|
|
|
|
|
import Icon from "@lib/components/Icon.svelte"
|
|
|
|
|
import PageContent from "@lib/components/PageContent.svelte"
|
|
|
|
|
import Spinner from "@lib/components/Spinner.svelte"
|
|
|
|
|
import Button from "@lib/components/Button.svelte"
|
2026-03-12 23:41:07 +00:00
|
|
|
import SpaceBar from "@app/components/SpaceBar.svelte"
|
2026-02-03 22:18:58 +00:00
|
|
|
import NoteContent from "@app/components/NoteContent.svelte"
|
2026-02-03 19:00:13 +00:00
|
|
|
import NoteCard from "@app/components/NoteCard.svelte"
|
|
|
|
|
import ClassifiedActions from "@app/components/ClassifiedActions.svelte"
|
|
|
|
|
import CommentActions from "@app/components/CommentActions.svelte"
|
|
|
|
|
import EventReply from "@app/components/EventReply.svelte"
|
2026-06-08 22:33:38 +00:00
|
|
|
import {deriveEvent} from "@app/repository"
|
|
|
|
|
import {decodeRelay} from "@app/relays"
|
2026-02-03 19:00:13 +00:00
|
|
|
|
2026-02-04 00:19:14 +00:00
|
|
|
const {relay, address} = $page.params as MakeNonOptional<typeof $page.params>
|
2026-02-03 19:00:13 +00:00
|
|
|
const url = decodeRelay(relay)
|
2026-02-04 00:19:14 +00:00
|
|
|
const event = deriveEvent(address, [url])
|
|
|
|
|
const filters = [{kinds: [COMMENT], "#A": [address]}]
|
2026-02-03 19:00:13 +00:00
|
|
|
const replies = deriveEventsAsc(deriveEventsById({filters, repository}))
|
|
|
|
|
|
|
|
|
|
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(() => {
|
|
|
|
|
const controller = new AbortController()
|
|
|
|
|
|
|
|
|
|
request({relays: [url], filters, signal: controller.signal})
|
|
|
|
|
|
|
|
|
|
return () => {
|
|
|
|
|
controller.abort()
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
</script>
|
|
|
|
|
|
2026-03-12 23:41:07 +00:00
|
|
|
<SpaceBar {back}>
|
2026-02-03 19:00:13 +00:00
|
|
|
{#snippet title()}
|
|
|
|
|
<h1 class="text-xl">{getTagValue("title", $event?.tags || []) || ""}</h1>
|
|
|
|
|
{/snippet}
|
2026-03-12 23:41:07 +00:00
|
|
|
</SpaceBar>
|
2026-02-03 19:00:13 +00:00
|
|
|
|
2026-06-22 20:36:57 +00:00
|
|
|
<PageContent class="flex flex-col gap-2 p-2 sm:gap-4 sm:p-4">
|
2026-02-03 19:00:13 +00:00
|
|
|
{#if $event}
|
|
|
|
|
<div class="flex flex-col gap-3">
|
2026-06-24 20:56:53 +00:00
|
|
|
<NoteCard event={$event} {url} class="card z-feature w-full">
|
|
|
|
|
<div class="flex flex-col gap-3 ml-12">
|
2026-02-03 22:18:58 +00:00
|
|
|
<NoteContent showEntire event={$event} {url} />
|
2026-02-03 19:00:13 +00:00
|
|
|
<ClassifiedActions showRoom event={$event} {url} />
|
|
|
|
|
</div>
|
|
|
|
|
</NoteCard>
|
|
|
|
|
{#if !showAll && $replies.length > 4}
|
|
|
|
|
<div class="flex justify-center">
|
2026-06-24 20:56:53 +00:00
|
|
|
<Button class="button button-link" onclick={expand}>
|
2026-02-03 19:00:13 +00:00
|
|
|
<Icon icon={SortVertical} />
|
|
|
|
|
Show all {$replies.length} replies
|
|
|
|
|
</Button>
|
|
|
|
|
</div>
|
|
|
|
|
{/if}
|
|
|
|
|
{#each $replies.slice(0, showAll ? undefined : 4) as reply (reply.id)}
|
2026-06-24 20:56:53 +00:00
|
|
|
<NoteCard event={reply} {url} class="card z-feature w-full">
|
|
|
|
|
<div class="flex flex-col gap-3 ml-12">
|
2026-02-03 22:18:58 +00:00
|
|
|
<NoteContent showEntire event={reply} {url} />
|
2026-02-03 19:00:13 +00:00
|
|
|
<CommentActions segment="classifieds" event={reply} {url} />
|
|
|
|
|
</div>
|
|
|
|
|
</NoteCard>
|
|
|
|
|
{/each}
|
|
|
|
|
</div>
|
|
|
|
|
{#if showReply}
|
|
|
|
|
<EventReply {url} event={$event} onClose={closeReply} onSubmit={closeReply} />
|
|
|
|
|
{:else}
|
2026-06-04 21:31:07 +00:00
|
|
|
<div class="flex justify-end">
|
2026-06-24 20:56:53 +00:00
|
|
|
<Button class="button button-primary" onclick={openReply}>
|
2026-02-03 19:00:13 +00:00
|
|
|
<Icon icon={Reply} />
|
|
|
|
|
Reply to listing
|
|
|
|
|
</Button>
|
|
|
|
|
</div>
|
|
|
|
|
{/if}
|
|
|
|
|
{:else}
|
2026-06-04 21:31:07 +00:00
|
|
|
<div class="flex justify-center py-20">
|
2026-02-04 00:19:14 +00:00
|
|
|
{#await sleep(5000)}
|
|
|
|
|
<Spinner loading>Loading listing...</Spinner>
|
|
|
|
|
{:then}
|
|
|
|
|
<p>Failed to load classified listing.</p>
|
|
|
|
|
{/await}
|
|
|
|
|
</div>
|
2026-02-03 19:00:13 +00:00
|
|
|
{/if}
|
|
|
|
|
</PageContent>
|