2026-09-23 02:35:06 +00:00
|
|
|
<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()
|
|
|
|
|
|
2026-09-24 18:23:21 +00:00
|
|
|
// A reaction goes where its subject lives: the space's own relay, or wherever the event was seen.
|
2026-09-23 02:35:06 +00:00
|
|
|
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: []})
|
2026-09-23 02:35:06 +00:00
|
|
|
</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>
|