flotilla/src/app/components/NoteItem.svelte

54 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"
import {Router} from "@welshman/router"
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"
2025-02-11 23:37:50 +00:00
import NoteContent from "@app/components/NoteContent.svelte"
2024-10-31 19:24:40 +00:00
import NoteCard from "@app/components/NoteCard.svelte"
import ReactionSummary from "@app/components/ReactionSummary.svelte"
import {publishDelete} from "@app/deletes"
import {publishReaction} from "@app/reactions"
import {canEnforceNip70} from "@app/relays"
2024-10-31 19:24:40 +00:00
2026-02-03 17:49:44 +00:00
type Props = {
event: TrustedEvent
children?: Snippet
url?: string
2026-02-03 17:49:44 +00:00
}
const {url, event, children}: Props = $props()
2024-10-31 19:24:40 +00:00
const relays = url ? [url] : Router.get().Event(event).getUrls()
const shouldProtect = url ? canEnforceNip70(url) : false
const deleteReaction = async (event: TrustedEvent) =>
publishDelete({relays, event, protect: await shouldProtect})
2024-10-31 19:24:40 +00:00
const createReaction = async (template: EventContent) =>
publishReaction({...template, event, relays, protect: await shouldProtect})
2024-10-31 19:24:40 +00:00
const onEmoji = async (emoji: NativeEmoji) =>
publishReaction({
event,
relays,
content: emoji.unicode,
protect: await shouldProtect,
})
2024-10-31 19:24:40 +00:00
</script>
<NoteCard {event} {url} class="cv card2">
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">
2025-05-12 22:10:24 +00:00
<ReactionSummary {url} {event} {deleteReaction} {createReaction} reactionClass="tooltip-right">
2024-10-31 19:24:40 +00:00
<EmojiButton {onEmoji} class="btn btn-neutral btn-xs h-[26px] rounded-box">
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>
</NoteCard>