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"
|
2026-07-28 16:16:26 +00:00
|
|
|
import {COMMENT} from "@welshman/util"
|
2026-07-02 18:36:05 +00:00
|
|
|
import GalleryWide from "@assets/icons/gallery-wide.svg?dataurl"
|
2025-10-06 18:23:19 +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
|
|
|
import Button from "@lib/components/Button.svelte"
|
2025-11-13 22:25:59 +00:00
|
|
|
import Confirm from "@lib/components/Confirm.svelte"
|
2025-02-06 17:29:30 +00:00
|
|
|
import Icon from "@lib/components/Icon.svelte"
|
|
|
|
|
import EventInfo from "@app/components/EventInfo.svelte"
|
2025-11-14 19:35:19 +00:00
|
|
|
import Report from "@app/components/Report.svelte"
|
2025-02-18 17:03:10 +00:00
|
|
|
import EventDeleteConfirm from "@app/components/EventDeleteConfirm.svelte"
|
2026-07-02 18:36:05 +00:00
|
|
|
import PinboardSelect from "@app/components/PinboardSelect.svelte"
|
2026-07-08 17:29:56 +00:00
|
|
|
import {shareEventToChat} from "@app/share"
|
2026-07-28 16:16:26 +00:00
|
|
|
import {deriveUserIsSpaceAdmin} from "@app/management"
|
2026-06-08 21:14:40 +00:00
|
|
|
import {pushModal} from "@app/modal"
|
|
|
|
|
import {pushToast} from "@app/toast"
|
2026-07-28 16:16:26 +00:00
|
|
|
import {app, relayManagement, user} from "@app/core"
|
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-11-13 22:25:59 +00:00
|
|
|
const userIsAdmin = deriveUserIsSpaceAdmin(url)
|
2025-02-06 17:29:30 +00:00
|
|
|
|
2025-11-14 19:35:19 +00:00
|
|
|
const report = () => pushModal(Report, {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
|
|
|
|
2026-07-27 22:16:21 +00:00
|
|
|
const addToLibrary = () => pushModal(PinboardSelect, {url, event})
|
2026-07-02 18:36:05 +00:00
|
|
|
|
2026-07-08 17:29:56 +00:00
|
|
|
const share = () => shareEventToChat(url, noun, event)
|
2025-02-06 17:29:30 +00:00
|
|
|
|
2025-03-18 22:36:52 +00:00
|
|
|
const showDelete = () => pushModal(EventDeleteConfirm, {url, event})
|
|
|
|
|
|
2025-11-13 22:25:59 +00:00
|
|
|
const showAdminDelete = () =>
|
|
|
|
|
pushModal(Confirm, {
|
|
|
|
|
title: `Delete ${noun}`,
|
|
|
|
|
message: `Are you sure you want to delete this ${noun.toLowerCase()} from the space?`,
|
|
|
|
|
confirm: async () => {
|
2026-07-28 16:16:26 +00:00
|
|
|
const {error} = await $relayManagement.forUrl(url).banEvent(event.id)
|
2025-11-13 22:25:59 +00:00
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
|
pushToast({theme: "error", message: error})
|
|
|
|
|
} else {
|
|
|
|
|
pushToast({message: "Event has successfully been deleted!"})
|
2026-07-28 16:16:26 +00:00
|
|
|
$app.repository.removeEvent(event.id)
|
2025-11-13 22:25:59 +00:00
|
|
|
history.back()
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
|
2025-03-18 22:36:52 +00:00
|
|
|
let ul: Element
|
|
|
|
|
|
|
|
|
|
onMount(() => {
|
|
|
|
|
ul.addEventListener("click", onClick)
|
|
|
|
|
})
|
2025-02-06 17:29:30 +00:00
|
|
|
</script>
|
|
|
|
|
|
2026-06-24 20:56:53 +00:00
|
|
|
<ul class="menu whitespace-nowrap rounded-2xl bg-surface p-2" bind:this={ul}>
|
2026-07-02 18:36:05 +00:00
|
|
|
<li>
|
|
|
|
|
<Button onclick={showInfo}>
|
|
|
|
|
<Icon size={4} icon={Code2} />
|
|
|
|
|
{noun} Details
|
|
|
|
|
</Button>
|
|
|
|
|
</li>
|
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>
|
2026-07-02 18:36:05 +00:00
|
|
|
<Button onclick={addToLibrary}>
|
|
|
|
|
<Icon size={4} icon={GalleryWide} />
|
|
|
|
|
Add to Library
|
2025-02-06 17:29:30 +00:00
|
|
|
</Button>
|
|
|
|
|
</li>
|
2025-03-18 22:36:52 +00:00
|
|
|
{@render customActions?.()}
|
2026-07-28 16:16:26 +00:00
|
|
|
{#if event.pubkey === $user.pubkey}
|
2025-02-06 17:29:30 +00:00
|
|
|
<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>
|
2025-11-13 22:25:59 +00:00
|
|
|
{#if $userIsAdmin}
|
|
|
|
|
<li>
|
|
|
|
|
<Button class="text-error" onclick={showAdminDelete}>
|
|
|
|
|
<Icon size={4} icon={TrashBin2} />
|
|
|
|
|
Delete {noun}
|
|
|
|
|
</Button>
|
|
|
|
|
</li>
|
|
|
|
|
{/if}
|
2025-02-06 17:29:30 +00:00
|
|
|
{/if}
|
|
|
|
|
</ul>
|