flotilla/src/app/components/EventMenu.svelte

78 lines
2.2 KiB
Svelte
Raw Normal View History

2025-02-06 17:29:30 +00:00
<script lang="ts">
2025-03-18 22:36:52 +00:00
import {onMount} from "svelte"
import type {Snippet} from "svelte"
2025-02-06 18:14:29 +00:00
import type {TrustedEvent} from "@welshman/util"
2025-02-06 17:29:30 +00:00
import {COMMENT} from "@welshman/util"
import {pubkey} from "@welshman/app"
import Button from "@lib/components/Button.svelte"
import Icon from "@lib/components/Icon.svelte"
import EventInfo from "@app/components/EventInfo.svelte"
import EventReport from "@app/components/EventReport.svelte"
2025-02-06 18:14:29 +00:00
import EventShare from "@app/components/EventShare.svelte"
import EventDeleteConfirm from "@app/components/EventDeleteConfirm.svelte"
import {pushModal} from "@app/util/modal"
2025-09-10 22:26:39 +00:00
import ShareCircle from "@assets/icons/share-circle.svg?dataurl"
import Code2 from "@assets/icons/code-2.svg?dataurl"
import TrashBin2 from "@assets/icons/trash-bin-2.svg?dataurl"
import Danger from "@assets/icons/danger.svg?dataurl"
2025-02-06 17:29:30 +00:00
2025-03-18 22:36:52 +00:00
type Props = {
2025-02-06 18:14:29 +00:00
url: string
noun: string
event: TrustedEvent
onClick: () => void
2025-03-18 22:36:52 +00:00
customActions?: Snippet
}
const {url, noun, event, onClick, customActions}: Props = $props()
2025-02-06 17:29:30 +00:00
const isRoot = event.kind !== COMMENT
2025-03-18 22:36:52 +00:00
const report = () => pushModal(EventReport, {url, event})
2025-02-06 17:29:30 +00:00
2025-03-18 22:36:52 +00:00
const showInfo = () => pushModal(EventInfo, {url, event})
2025-02-06 17:29:30 +00:00
2025-03-18 22:36:52 +00:00
const share = () => pushModal(EventShare, {url, event})
2025-02-06 17:29:30 +00:00
2025-03-18 22:36:52 +00:00
const showDelete = () => pushModal(EventDeleteConfirm, {url, event})
let ul: Element
onMount(() => {
ul.addEventListener("click", onClick)
})
2025-02-06 17:29:30 +00:00
</script>
2025-03-18 22:36:52 +00:00
<ul class="menu whitespace-nowrap rounded-box bg-base-100 p-2 shadow-xl" bind:this={ul}>
2025-02-06 17:29:30 +00:00
{#if isRoot}
<li>
<Button onclick={share}>
2025-09-10 22:26:39 +00:00
<Icon size={4} icon={ShareCircle} />
2025-02-06 17:29:30 +00:00
Share to Chat
</Button>
</li>
{/if}
<li>
<Button onclick={showInfo}>
2025-09-10 22:26:39 +00:00
<Icon size={4} icon={Code2} />
2025-02-06 18:14:29 +00:00
{noun} Details
2025-02-06 17:29:30 +00:00
</Button>
</li>
2025-03-18 22:36:52 +00:00
{@render customActions?.()}
2025-02-06 17:29:30 +00:00
{#if event.pubkey === $pubkey}
<li>
<Button onclick={showDelete} class="text-error">
2025-09-10 22:26:39 +00:00
<Icon size={4} icon={TrashBin2} />
2025-02-06 18:14:29 +00:00
Delete {noun}
2025-02-06 17:29:30 +00:00
</Button>
</li>
{:else}
<li>
<Button class="text-error" onclick={report}>
2025-09-10 22:26:39 +00:00
<Icon size={4} icon={Danger} />
2025-02-06 17:29:30 +00:00
Report Content
</Button>
</li>
{/if}
</ul>