Add handler for alerts

This commit is contained in:
Jon Staab
2025-03-20 09:38:57 -07:00
parent ad034b1641
commit 9eefd6600d
9 changed files with 123 additions and 45 deletions
+56
View File
@@ -0,0 +1,56 @@
<script lang="ts">
import {onMount} from "svelte"
import * as nip19 from "nostr-tools/nip19"
import type {TrustedEvent} from "@welshman/util"
import {Address, getIdFilters, getTagValue} from "@welshman/util"
import {load} from "@welshman/app"
import {page} from "$app/stores"
import {goto} from "$app/navigation"
import {scrollToEvent} from "@lib/html"
import Spinner from "@lib/components/Spinner.svelte"
import {makeRoomPath, makeThreadPath} from "@app/routes"
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
load({
filters: getIdFilters([type === "nevent" ? data.id : Address.fromNaddr(bech32).toString()]),
relays: data.relays,
onEvent: (event: TrustedEvent) => {
found = true
if (event.kind === 9) {
goto(makeRoomPath(data.relays[0], getTagValue("h", event.tags)!), {replaceState: true})
scrollToEvent(event.id)
} else if (event.kind === 11) {
goto(makeThreadPath(data.relays[0], event.id), {replaceState: true})
} else {
goto("/", {replaceState: true})
}
},
onComplete: () => {
if (!found) {
goto("/", {replaceState: true})
}
},
})
}
onMount(async () => {
try {
await attemptToNavigate()
} catch (e) {
goto("/", {replaceState: true})
}
})
</script>
<Spinner />
+2
View File
@@ -12,6 +12,7 @@
import ProfileEdit from "@app/components/ProfileEdit.svelte"
import ProfileDelete from "@app/components/ProfileDelete.svelte"
import InfoKeys from "@app/components/InfoKeys.svelte"
import Alerts from "@app/components/Alerts.svelte"
import {PLATFORM_NAME} from "@app/state"
import {pushModal} from "@app/modal"
import {clip} from "@app/toast"
@@ -129,6 +130,7 @@
</FieldInline>
{/if}
</div>
<Alerts />
<div class="card2 bg-alt shadow-xl">
<div class="flex items-center justify-between">
<strong class="flex items-center gap-3">