flotilla/src/app/components/ContentActions.svelte

95 lines
2.8 KiB
Svelte
Raw Normal View History

2025-02-06 17:29:30 +00:00
<script lang="ts">
import type {Component, Snippet} from "svelte"
2025-05-12 22:10:24 +00:00
import type {TrustedEvent, EventContent} from "@welshman/util"
import {tagSpec, tagValue} from "@welshman/util"
import Pen2 from "@assets/icons/pen-2.svg?dataurl"
2025-03-18 22:36:52 +00:00
import Icon from "@lib/components/Icon.svelte"
import Button from "@lib/components/Button.svelte"
2025-10-06 18:23:19 +00:00
import Link from "@lib/components/Link.svelte"
2025-10-30 22:36:14 +00:00
import RoomName from "@app/components/RoomName.svelte"
2025-02-06 17:29:30 +00:00
import ReactionSummary from "@app/components/ReactionSummary.svelte"
2025-02-06 17:39:23 +00:00
import ThunkStatusOrDeleted from "@app/components/ThunkStatusOrDeleted.svelte"
2025-02-06 17:53:50 +00:00
import EventActivity from "@app/components/EventActivity.svelte"
2025-02-06 18:00:25 +00:00
import EventActions from "@app/components/EventActions.svelte"
2026-07-28 16:16:26 +00:00
import {user} from "@app/core"
import type {FeedContext} from "@app/feeds"
import {publishReaction, retractReaction} from "@app/reactions"
import {makeSpacePath} from "@app/routes"
2026-06-08 21:14:40 +00:00
import {pushModal} from "@app/modal"
2025-02-06 17:29:30 +00:00
type EditForm = Component<{url: string; event: TrustedEvent}>
2025-10-06 18:23:19 +00:00
type Props = {
2025-02-06 17:53:50 +00:00
url: string
event: TrustedEvent
context: FeedContext
noun: string
2025-10-06 18:23:19 +00:00
showRoom?: boolean
2025-02-06 17:29:30 +00:00
showActivity?: boolean
hideZap?: boolean
editForm?: EditForm
labels?: Snippet
status?: Snippet
2025-10-06 18:23:19 +00:00
}
2025-02-06 17:29:30 +00:00
const {
url,
event,
context,
noun,
showRoom,
showActivity,
hideZap,
editForm,
labels,
status,
}: Props = $props()
2026-08-22 20:12:11 +00:00
const h = $derived(tagValue(tagSpec("h"), event.tags))
2025-02-06 17:29:30 +00:00
const edit = (form: EditForm) => () => pushModal(form, {url, event})
2025-03-18 22:36:52 +00:00
const deleteReaction = (reaction: TrustedEvent) => retractReaction(reaction, {url})
2025-02-06 17:29:30 +00:00
const createReaction = (values: EventContent) => publishReaction(event, values, {url})
2025-02-06 17:29:30 +00:00
</script>
<div class="flex grow flex-wrap items-center justify-end gap-2">
{#if (h && showRoom) || labels}
<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}
{@render labels?.()}
</div>
<span class="h-6 w-px shrink-0 bg-line"></span>
2025-10-06 18:23:19 +00:00
{/if}
<ThunkStatusOrDeleted {event} {context} {status}>
<ReactionSummary
{url}
{event}
{context}
{deleteReaction}
{createReaction}
hideZaps={hideZap}
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} {hideZap} {noun}>
2026-08-21 15:31:53 +00:00
{#snippet customActions()}
{#if editForm && event.pubkey === $user.pubkey}
2026-08-21 15:31:53 +00:00
<li>
<Button onclick={edit(editForm)}>
2026-08-21 15:31:53 +00:00
<Icon size={4} icon={Pen2} />
Edit {noun}
2026-08-21 15:31:53 +00:00
</Button>
</li>
{/if}
{/snippet}
</EventActions>
</ThunkStatusOrDeleted>
2025-02-06 17:29:30 +00:00
</div>