flotilla/src/app/components/ContentQuote.svelte

65 lines
2 KiB
Svelte
Raw Normal View History

2024-09-24 21:12:38 +00:00
<script lang="ts">
2025-04-09 22:32:18 +00:00
import * as nip19 from "nostr-tools/nip19"
import {Router} from "@welshman/router"
2025-04-15 18:03:27 +00:00
import type {TrustedEvent} from "@welshman/util"
2025-06-05 17:55:16 +00:00
import {Address, MESSAGE} from "@welshman/util"
import Button from "@lib/components/Button.svelte"
2024-10-01 21:55:33 +00:00
import Spinner from "@lib/components/Spinner.svelte"
2024-09-24 21:12:38 +00:00
import NoteCard from "@app/components/NoteCard.svelte"
2025-02-11 23:37:50 +00:00
import NoteContent from "@app/components/NoteContent.svelte"
import {deriveEvent, entityLink} from "@app/core/state"
import {goToEvent} from "@app/util/routes"
2024-09-24 21:12:38 +00:00
2025-04-15 18:03:27 +00:00
type Props = {
value: any
hideMediaAtDepth: number
event: TrustedEvent
depth: number
url?: string
minimal?: boolean
2025-04-15 18:03:27 +00:00
}
const {value, event, depth, hideMediaAtDepth, url, minimal}: Props = $props()
2024-09-24 21:12:38 +00:00
2025-04-15 18:03:27 +00:00
const {id, identifier, kind, pubkey, relays = []} = value
const idOrAddress = id || new Address(kind, pubkey, identifier).toString()
2025-04-15 18:03:27 +00:00
const mergedRelays = Router.get().Quote(event, idOrAddress, relays).getUrls()
if (url) {
mergedRelays.push(url)
}
const quote = deriveEvent(idOrAddress, mergedRelays)
const entity = id
? nip19.neventEncode({id, relays: mergedRelays})
: new Address(kind, pubkey, identifier, mergedRelays).toNaddr()
2024-10-24 16:21:34 +00:00
const onclick = () => {
if ($quote) {
2025-06-05 17:55:16 +00:00
goToEvent($quote)
} else {
window.open(entityLink(entity))
}
}
2024-09-24 21:12:38 +00:00
</script>
<Button class="my-2 block max-w-full text-left" {onclick}>
2024-11-18 22:39:43 +00:00
{#if $quote}
{#if minimal && $quote.kind === MESSAGE}
<div
class="border-l-2 border-solid border-l-primary py-1 pl-2 opacity-90"
style="background-color: color-mix(in srgb, var(--primary) 10%, var(--base-300) 90%);">
<NoteContent {hideMediaAtDepth} {url} event={$quote} depth={depth + 1} />
</div>
{:else}
<NoteCard event={$quote} {url} class="bg-alt rounded-box p-4">
<NoteContent {hideMediaAtDepth} {url} event={$quote} depth={depth + 1} />
</NoteCard>
{/if}
2024-10-01 21:55:33 +00:00
{:else}
2024-10-08 18:39:16 +00:00
<div class="rounded-box p-4">
2024-10-01 21:55:33 +00:00
<Spinner loading>Loading event...</Spinner>
</div>
{/if}
</Button>