flotilla/src/app/components/EventMenu.svelte

74 lines
1.9 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"
2025-02-06 17:29:30 +00:00
import {pushModal} from "@app/modal"
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}>
<Icon size={4} icon="share-circle" />
Share to Chat
</Button>
</li>
{/if}
<li>
<Button onclick={showInfo}>
<Icon size={4} icon="code-2" />
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">
<Icon size={4} icon="trash-bin-2" />
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}>
<Icon size={4} icon="danger" />
Report Content
</Button>
</li>
{/if}
</ul>