2025-03-20 16:38:57 +00:00
|
|
|
<script lang="ts">
|
|
|
|
|
import {onMount} from "svelte"
|
|
|
|
|
import * as nip19 from "nostr-tools/nip19"
|
|
|
|
|
import type {TrustedEvent} from "@welshman/util"
|
2025-06-24 21:15:36 +00:00
|
|
|
import {Address, getIdFilters} from "@welshman/util"
|
2025-06-19 17:22:17 +00:00
|
|
|
import {LOCAL_RELAY_URL} from "@welshman/relay"
|
2025-04-11 21:44:27 +00:00
|
|
|
import {load} from "@welshman/net"
|
2025-03-20 16:38:57 +00:00
|
|
|
import {page} from "$app/stores"
|
|
|
|
|
import {goto} from "$app/navigation"
|
|
|
|
|
import Spinner from "@lib/components/Spinner.svelte"
|
2025-06-19 17:22:17 +00:00
|
|
|
import {goToEvent} from "@app/routes"
|
2025-03-20 16:38:57 +00:00
|
|
|
|
|
|
|
|
const {bech32} = $page.params
|
|
|
|
|
|
|
|
|
|
const attemptToNavigate = async () => {
|
|
|
|
|
const {type, data} = nip19.decode(bech32) as any
|
|
|
|
|
|
|
|
|
|
if (!["nevent", "naddr"].includes(type) && data.relays.length > 0) {
|
|
|
|
|
return goto("/", {replaceState: true})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let found = false
|
|
|
|
|
|
2025-04-11 21:44:27 +00:00
|
|
|
load({
|
2025-06-19 17:22:17 +00:00
|
|
|
relays: [LOCAL_RELAY_URL, ...data.relays],
|
2025-04-11 21:44:27 +00:00
|
|
|
filters: getIdFilters([type === "nevent" ? data.id : Address.fromNaddr(bech32).toString()]),
|
2025-04-11 16:27:19 +00:00
|
|
|
onEvent: (event: TrustedEvent) => {
|
|
|
|
|
found = true
|
2025-06-19 17:22:17 +00:00
|
|
|
goToEvent(event, {replaceState: true})
|
2025-04-11 16:27:19 +00:00
|
|
|
},
|
|
|
|
|
onClose: () => {
|
|
|
|
|
if (!found) {
|
|
|
|
|
goto("/", {replaceState: true})
|
|
|
|
|
}
|
|
|
|
|
},
|
2025-03-20 16:38:57 +00:00
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onMount(async () => {
|
|
|
|
|
try {
|
|
|
|
|
await attemptToNavigate()
|
|
|
|
|
} catch (e) {
|
|
|
|
|
goto("/", {replaceState: true})
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<Spinner />
|