flotilla/src/app/components/ClassifiedActions.svelte

114 lines
3.8 KiB
Svelte
Raw Normal View History

2026-02-03 19:00:13 +00:00
<script lang="ts">
import {uniq} from "@welshman/lib"
2026-02-03 19:00:13 +00:00
import type {TrustedEvent, EventContent} from "@welshman/util"
2026-07-28 16:16:26 +00:00
import {Classified} from "@welshman/domain"
import {goto} from "$app/navigation"
import Pen2 from "@assets/icons/pen-2.svg?dataurl"
import {normalizeTopic} from "@lib/util"
2026-02-03 19:00:13 +00:00
import Link from "@lib/components/Link.svelte"
import Icon from "@lib/components/Icon.svelte"
import Button from "@lib/components/Button.svelte"
2026-02-03 19:00:13 +00:00
import RoomName from "@app/components/RoomName.svelte"
2026-07-28 16:16:26 +00:00
import {publishReaction, retractReaction} from "@app/reactions"
2026-02-03 19:00:13 +00:00
import ReactionSummary from "@app/components/ReactionSummary.svelte"
import type {FeedContext} from "@app/feeds"
2026-02-04 01:09:30 +00:00
import ClassifiedStatus from "@app/components/ClassifiedStatus.svelte"
2026-02-03 19:00:13 +00:00
import ThunkStatusOrDeleted from "@app/components/ThunkStatusOrDeleted.svelte"
import EventActivity from "@app/components/EventActivity.svelte"
import EventActions from "@app/components/EventActions.svelte"
import ClassifiedEdit from "@app/components/ClassifiedEdit.svelte"
2026-07-28 16:16:26 +00:00
import {reader, user} from "@app/core"
import {makeClassifiedPath, makeSpacePath} from "@app/routes"
2026-06-08 21:14:40 +00:00
import {pushModal} from "@app/modal"
2026-02-03 19:00:13 +00:00
2026-07-28 16:16:26 +00:00
type Props = {
2026-02-03 19:00:13 +00:00
url: string
event: TrustedEvent
showRoom?: boolean
showActivity?: boolean
context: FeedContext
// The grid card lays these out itself, so it opts out of both.
showTopics?: boolean
showStatus?: boolean
2026-02-03 19:00:13 +00:00
}
const {
url,
event,
showRoom,
showActivity,
context,
showTopics = true,
showStatus = true,
}: Props = $props()
2026-02-03 19:00:13 +00:00
// Editing hands this a new version of the event, so every value is recomputed rather than captured.
2026-08-22 20:12:11 +00:00
const classified = $derived(reader(Classified)(event))
const h = $derived(classified.room())
const topics = $derived(classified.topics() ?? [])
2026-02-03 19:00:13 +00:00
const editClassified = () => pushModal(ClassifiedEdit, {url, event})
const filterByTopic = (topic: string) => (e: MouseEvent) => {
e.stopPropagation()
e.preventDefault()
goto(`${makeClassifiedPath(url)}?topic=${encodeURIComponent(normalizeTopic(topic))}`)
}
2026-07-28 16:16:26 +00:00
const deleteReaction = (reaction: TrustedEvent) => retractReaction(reaction, {url, h})
2026-02-03 19:00:13 +00:00
2026-07-28 16:16:26 +00:00
const createReaction = (values: EventContent) => publishReaction(event, values, {url, h})
2026-02-03 19:00:13 +00:00
</script>
<div class="flex grow flex-wrap items-center justify-end gap-2">
{#if (h && showRoom) || (showTopics && uniq(topics).length > 0)}
<div class="flex min-w-0 flex-wrap items-center gap-2">
{#if h && showRoom}
<Link href={makeSpacePath(url, h)} class="button button-neutral button-xs rounded-full">
Posted in #<RoomName {h} {url} />
</Link>
{/if}
{#if showTopics}
{#each uniq(topics) as topic (topic)}
<button
type="button"
class="badge badge-neutral badge-sm cursor-pointer font-normal"
onclick={filterByTopic(topic)}>
#{normalizeTopic(topic)}
</button>
{/each}
{/if}
</div>
<span class="h-6 w-px shrink-0 bg-line"></span>
2026-02-03 19:00:13 +00:00
{/if}
2026-08-31 17:03:01 +00:00
<ThunkStatusOrDeleted {event} {context}>
2026-08-21 15:31:53 +00:00
{#snippet status()}
{#if showStatus}
<ClassifiedStatus {event} />
{/if}
{/snippet}
<ReactionSummary
{url}
{event}
{context}
{deleteReaction}
{createReaction}
reactionClass="tip-left" />
2026-08-21 15:31:53 +00:00
{#if showActivity}
<EventActivity {event} {context} />
2026-08-21 15:31:53 +00:00
{/if}
<EventActions {url} {event} noun="Listing">
{#snippet customActions()}
{#if event.pubkey === $user.pubkey}
<li>
<Button onclick={editClassified}>
<Icon size={4} icon={Pen2} />
Edit Listing
</Button>
</li>
{/if}
{/snippet}
</EventActions>
</ThunkStatusOrDeleted>
2026-02-03 19:00:13 +00:00
</div>