flotilla/src/app/components/EventReactions.svelte

41 lines
1.5 KiB
Svelte
Raw Normal View History

<script lang="ts">
import type {TrustedEvent, EventContent} from "@welshman/util"
import {seen} from "@welshman/util"
import SmileCircle from "@assets/icons/smile-circle.svg?dataurl"
import Icon from "@lib/components/Icon.svelte"
import EmojiButton from "@lib/components/EmojiButton.svelte"
import ReactionSummary from "@app/components/ReactionSummary.svelte"
import {publishReaction, retractReaction} from "@app/reactions"
import type {FeedContext} from "@app/feeds"
import {router} from "@app/core"
type Props = {
event: TrustedEvent
context: FeedContext
url?: string
reactionClass?: string
}
const {event, context, url, reactionClass = ""}: Props = $props()
// A reaction goes where its subject lives: the space's own relay, or wherever the event was seen.
const getRelays = () => (url ? [url] : $router.resolver.relays([seen(event)]))
const deleteReaction = async (reaction: TrustedEvent) =>
retractReaction(reaction, {url, urls: await getRelays()})
const createReaction = async (values: EventContent) =>
publishReaction(event, values, {url, urls: await getRelays()})
2026-09-25 20:32:44 +00:00
const onEmoji = (emoji: string) => createReaction({content: emoji, tags: []})
</script>
<ReactionSummary {url} {event} {context} {deleteReaction} {createReaction} {reactionClass}>
<EmojiButton
{onEmoji}
aria-label="Add a reaction"
class="button button-neutral button-xs rounded-full">
<Icon icon={SmileCircle} size={4} />
</EmojiButton>
</ReactionSummary>