flotilla/src/app/components/CalendarEventActions.svelte

65 lines
2.4 KiB
Svelte
Raw Normal View History

2025-02-06 17:29:30 +00:00
<script lang="ts">
2025-05-12 22:10:24 +00:00
import type {TrustedEvent, EventContent} from "@welshman/util"
2025-10-06 18:23:19 +00:00
import {getTagValue} from "@welshman/util"
2025-02-06 17:53:50 +00:00
import {pubkey} from "@welshman/app"
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"
import ChannelName from "@app/components/ChannelName.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"
2025-03-18 22:36:52 +00:00
import CalendarEventEdit from "@app/components/CalendarEventEdit.svelte"
import {publishDelete, publishReaction, canEnforceNip70} from "@app/core/commands"
2025-10-06 18:23:19 +00:00
import {makeCalendarPath, makeSpacePath} from "@app/util/routes"
import {pushModal} from "@app/util/modal"
2025-09-10 22:26:39 +00:00
import Pen2 from "@assets/icons/pen-2.svg?dataurl"
2025-02-06 17:29:30 +00:00
2025-10-06 18:23:19 +00:00
type Props = {
2025-02-06 17:53:50 +00:00
url: string
event: TrustedEvent
2025-10-06 18:23:19 +00:00
showRoom?: boolean
2025-02-06 17:29:30 +00:00
showActivity?: boolean
2025-10-06 18:23:19 +00:00
}
2025-02-06 17:29:30 +00:00
2025-10-06 18:23:19 +00:00
const {url, event, showRoom, showActivity}: Props = $props()
2025-10-06 18:23:19 +00:00
const room = getTagValue("h", event.tags)
2025-02-06 17:29:30 +00:00
const path = makeCalendarPath(url, event.id)
2025-10-06 18:23:19 +00:00
const shouldProtect = canEnforceNip70(url)
2025-02-06 17:29:30 +00:00
2025-03-18 22:36:52 +00:00
const editEvent = () => pushModal(CalendarEventEdit, {url, event})
const deleteReaction = async (event: TrustedEvent) =>
publishDelete({relays: [url], event, protect: await shouldProtect})
2025-02-06 17:29:30 +00:00
const createReaction = async (template: EventContent) =>
publishReaction({...template, event, relays: [url], protect: await shouldProtect})
2025-02-06 17:29:30 +00:00
</script>
2025-10-06 18:23:19 +00:00
<div class="flex flex-grow flex-wrap justify-end gap-2">
{#if room && showRoom}
<Link href={makeSpacePath(url, room)} class="btn btn-neutral btn-xs rounded-full">
Posted in #<ChannelName {room} {url} />
</Link>
{/if}
<ReactionSummary {url} {event} {deleteReaction} {createReaction} reactionClass="tooltip-left" />
<ThunkStatusOrDeleted {event} />
{#if showActivity}
<EventActivity {url} {path} {event} />
{/if}
<EventActions {url} {event} noun="Event">
{#snippet customActions()}
{#if event.pubkey === $pubkey}
<li>
<Button onclick={editEvent}>
<Icon size={4} icon={Pen2} />
Edit Event
</Button>
</li>
{/if}
{/snippet}
</EventActions>
2025-02-06 17:29:30 +00:00
</div>