flotilla/src/app/components/ThreadActions.svelte

70 lines
2.4 KiB
Svelte
Raw Normal View History

2024-10-23 23:16:28 +00:00
<script lang="ts">
import {type Instance} from "tippy.js"
import type {NativeEmoji} from "emoji-picker-element/shared"
import type {TrustedEvent} from "@welshman/util"
2025-02-06 17:53:50 +00:00
import {pubkey} from "@welshman/app"
2024-10-23 23:16:28 +00:00
import Icon from "@lib/components/Icon.svelte"
import Tippy from "@lib/components/Tippy.svelte"
import Button from "@lib/components/Button.svelte"
import EmojiButton from "@lib/components/EmojiButton.svelte"
import ReactionSummary from "@app/components/ReactionSummary.svelte"
2025-02-06 17:39:23 +00:00
import ThunkStatusOrDeleted from "@app/components/ThunkStatusOrDeleted.svelte"
2024-10-23 23:16:28 +00:00
import ThreadMenu from "@app/components/ThreadMenu.svelte"
2025-02-06 17:53:50 +00:00
import EventActivity from "@app/components/EventActivity.svelte"
2024-10-23 23:16:28 +00:00
import {publishDelete, publishReaction} from "@app/commands"
2025-02-06 17:29:30 +00:00
import {makeThreadPath} from "@app/routes"
2024-10-23 23:16:28 +00:00
2025-02-04 00:37:14 +00:00
interface Props {
url: any
event: any
showActivity?: boolean
}
const {url, event, showActivity = false}: Props = $props()
2025-02-06 17:29:30 +00:00
const path = makeThreadPath(url, event.id)
2024-10-23 23:16:28 +00:00
2025-02-04 00:37:14 +00:00
const showPopover = () => popover?.show()
2024-10-23 23:16:28 +00:00
2025-02-04 00:37:14 +00:00
const hidePopover = () => popover?.hide()
2024-10-23 23:16:28 +00:00
const onReactionClick = (content: string, events: TrustedEvent[]) => {
const reaction = events.find(e => e.pubkey === $pubkey)
if (reaction) {
publishDelete({relays: [url], event: reaction})
} else {
publishReaction({event, content, relays: [url]})
2024-10-23 23:16:28 +00:00
}
}
const onEmoji = (emoji: NativeEmoji) =>
publishReaction({event, content: emoji.unicode, relays: [url]})
2024-10-23 23:16:28 +00:00
2025-02-04 00:37:14 +00:00
let popover: Instance | undefined = $state()
2024-10-23 23:16:28 +00:00
</script>
2024-10-24 16:58:43 +00:00
<div class="flex flex-wrap items-center justify-between gap-2">
2024-10-31 19:24:40 +00:00
<div class="flex flex-grow flex-wrap justify-end gap-2">
2025-01-15 01:23:27 +00:00
<ReactionSummary {url} {event} {onReactionClick} reactionClass="tooltip-left" />
2025-02-06 17:39:23 +00:00
<ThunkStatusOrDeleted {event} />
{#if showActivity}
2025-02-06 17:53:50 +00:00
<EventActivity {url} {path} {event} />
{/if}
2024-10-24 17:11:01 +00:00
<Button class="join rounded-full">
2024-10-24 22:48:45 +00:00
<EmojiButton {onEmoji} class="btn join-item btn-neutral btn-xs">
<Icon icon="smile-circle" size={4} />
</EmojiButton>
<Tippy
bind:popover
component={ThreadMenu}
props={{url, event, onClick: hidePopover}}
params={{trigger: "manual", interactive: true}}>
<Button class="btn join-item btn-neutral btn-xs" onclick={showPopover}>
<Icon icon="menu-dots" size={4} />
</Button>
</Tippy>
2024-10-24 17:11:01 +00:00
</Button>
2024-10-23 23:16:28 +00:00
</div>
</div>