flotilla/src/app/components/NoteItem.svelte

57 lines
1.9 KiB
Svelte
Raw Normal View History

2024-10-31 19:24:40 +00:00
<script lang="ts">
2026-02-03 17:49:44 +00:00
import type {Snippet} from "svelte"
2024-10-31 19:24:40 +00:00
import type {NativeEmoji} from "emoji-picker-element/shared"
2025-05-12 22:10:24 +00:00
import type {TrustedEvent, EventContent} from "@welshman/util"
2026-07-28 16:16:26 +00:00
import {seen} from "@welshman/util"
2025-09-10 22:26:39 +00:00
import SmileCircle from "@assets/icons/smile-circle.svg?dataurl"
2024-10-31 19:24:40 +00:00
import Icon from "@lib/components/Icon.svelte"
import EmojiButton from "@lib/components/EmojiButton.svelte"
import Cv from "@lib/components/Cv.svelte"
2025-02-11 23:37:50 +00:00
import NoteContent from "@app/components/NoteContent.svelte"
2026-07-28 16:16:26 +00:00
import {publishReaction, retractReaction} from "@app/reactions"
2024-10-31 19:24:40 +00:00
import NoteCard from "@app/components/NoteCard.svelte"
import ReactionSummary from "@app/components/ReactionSummary.svelte"
import type {FeedContext} from "@app/feeds"
2026-07-28 16:16:26 +00:00
import {router} from "@app/core"
2024-10-31 19:24:40 +00:00
2026-02-03 17:49:44 +00:00
type Props = {
event: TrustedEvent
children?: Snippet
context: FeedContext
url?: string
2026-02-03 17:49:44 +00:00
}
const {url, event, children, context}: Props = $props()
2024-10-31 19:24:40 +00:00
2026-07-28 16:16:26 +00:00
const getRelays = () => (url ? [url] : $router.resolver.relays([seen(event)]))
2026-07-28 16:16:26 +00:00
const deleteReaction = async (reaction: TrustedEvent) =>
retractReaction(reaction, {url, urls: await getRelays()})
2026-07-28 16:16:26 +00:00
const createReaction = async (values: EventContent) =>
publishReaction(event, values, {url, urls: await getRelays()})
2024-10-31 19:24:40 +00:00
2026-07-28 16:16:26 +00:00
const onEmoji = (emoji: NativeEmoji) => createReaction({content: emoji.unicode, tags: []})
2024-10-31 19:24:40 +00:00
</script>
<Cv tag={NoteCard} {event} {url} class="card card-interactive">
2025-02-11 23:37:50 +00:00
<NoteContent {event} expandMode="inline" />
2024-10-31 19:24:40 +00:00
<div class="flex w-full justify-between gap-2">
<ReactionSummary
{url}
{event}
{context}
{deleteReaction}
{createReaction}
reactionClass="tip-right">
<EmojiButton
{onEmoji}
aria-label="Add a reaction"
class="button button-neutral button-xs rounded-full">
2025-09-10 22:26:39 +00:00
<Icon icon={SmileCircle} size={4} />
2024-10-31 19:24:40 +00:00
</EmojiButton>
</ReactionSummary>
2026-02-03 17:49:44 +00:00
{@render children?.()}
2024-10-31 19:24:40 +00:00
</div>
</Cv>