flotilla/src/app/components/EventActions.svelte

59 lines
1.8 KiB
Svelte
Raw Normal View History

2025-02-06 18:00:25 +00:00
<script lang="ts">
2025-03-18 22:36:52 +00:00
import type {Snippet} from "svelte"
2025-02-06 18:00:25 +00:00
import type {Instance} from "tippy.js"
import type {NativeEmoji} from "emoji-picker-element/shared"
import type {TrustedEvent} from "@welshman/util"
import Icon from "@lib/components/Icon.svelte"
import Tippy from "@lib/components/Tippy.svelte"
import Button from "@lib/components/Button.svelte"
2025-07-15 22:56:55 +00:00
import ZapButton from "@app/components/ZapButton.svelte"
2025-02-06 18:00:25 +00:00
import EmojiButton from "@lib/components/EmojiButton.svelte"
2025-02-06 18:14:29 +00:00
import EventMenu from "@app/components/EventMenu.svelte"
2025-07-17 21:39:59 +00:00
import {ENABLE_ZAPS} from "@app/state"
import {publishReaction, canEnforceNip70} from "@app/commands"
2025-02-06 18:00:25 +00:00
2025-03-18 22:36:52 +00:00
type Props = {
2025-02-06 18:00:25 +00:00
url: string
2025-02-06 18:14:29 +00:00
noun: string
2025-02-06 18:00:25 +00:00
event: TrustedEvent
2025-07-15 22:56:55 +00:00
hideZap?: boolean
2025-03-18 22:36:52 +00:00
customActions?: Snippet
}
2025-07-15 22:56:55 +00:00
const {url, noun, event, hideZap, customActions}: Props = $props()
2025-02-06 18:00:25 +00:00
const showPopover = () => popover?.show()
const hidePopover = () => popover?.hide()
const onEmoji = async (emoji: NativeEmoji) =>
publishReaction({
event,
content: emoji.unicode,
relays: [url],
protect: await canEnforceNip70(url),
})
2025-02-06 18:00:25 +00:00
let popover: Instance | undefined = $state()
</script>
<Button class="join rounded-full">
2025-07-17 21:39:59 +00:00
{#if ENABLE_ZAPS && !hideZap}
2025-07-15 22:56:55 +00:00
<ZapButton {url} {event} class="btn join-item btn-neutral btn-xs">
<Icon icon="bolt" size={4} />
</ZapButton>
{/if}
2025-02-06 18:00:25 +00:00
<EmojiButton {onEmoji} class="btn join-item btn-neutral btn-xs">
<Icon icon="smile-circle" size={4} />
</EmojiButton>
<Tippy
bind:popover
2025-02-06 18:14:29 +00:00
component={EventMenu}
2025-03-18 22:36:52 +00:00
props={{url, noun, event, customActions, onClick: hidePopover}}
2025-02-06 18:00:25 +00:00
params={{trigger: "manual", interactive: true}}>
<Button class="btn join-item btn-neutral btn-xs" onclick={showPopover}>
<Icon icon="menu-dots" size={4} />
</Button>
</Tippy>
</Button>