1 changed files with 8 additions and 32 deletions
@ -1,42 +1,18 @@ |
|||||||
<script lang="ts"> |
<script lang='ts'> |
||||||
import { page } from '$app/stores'; |
|
||||||
import Article from '$lib/components/Article.svelte'; |
import Article from '$lib/components/Article.svelte'; |
||||||
import { ndk } from '$lib/ndk'; |
|
||||||
import type { NDKEvent } from '@nostr-dev-kit/ndk'; |
|
||||||
import { TextPlaceholder } from 'flowbite-svelte'; |
import { TextPlaceholder } from 'flowbite-svelte'; |
||||||
|
import type { PageData } from './$types'; |
||||||
|
import { onDestroy } from 'svelte'; |
||||||
|
|
||||||
const id = $page.url.searchParams.get('id'); |
let { data }: { data: PageData } = $props(); |
||||||
const dTag = $page.url.searchParams.get('d'); |
|
||||||
|
|
||||||
let event: NDKEvent | null | undefined; |
onDestroy(() => data.parser.reset()); |
||||||
|
|
||||||
if (id) { |
|
||||||
$ndk.fetchEvent(id) |
|
||||||
.then(ev => { |
|
||||||
event = ev; |
|
||||||
}) |
|
||||||
.catch(err => { |
|
||||||
console.error(err); |
|
||||||
// TODO: Redirect to 404 page. |
|
||||||
}); |
|
||||||
} else if (dTag) { |
|
||||||
$ndk.fetchEvent({ '#d': [dTag] }) |
|
||||||
.then(ev => { |
|
||||||
event = ev; |
|
||||||
}) |
|
||||||
.catch(err => { |
|
||||||
console.error(err); |
|
||||||
// TODO: Redirect to 404 page. |
|
||||||
}); |
|
||||||
} else { |
|
||||||
// TODO: Redirect to 400 page. |
|
||||||
} |
|
||||||
</script> |
</script> |
||||||
|
|
||||||
<main> |
<main> |
||||||
{#await event} |
{#await data.waitable} |
||||||
<TextPlaceholder size='xxl' /> |
<TextPlaceholder size='xxl' /> |
||||||
{:then ev} |
{:then} |
||||||
<Article index={ev} /> |
<Article rootId={data.parser.getRootIndexId()} /> |
||||||
{/await} |
{/await} |
||||||
</main> |
</main> |
||||||
|
|||||||
Loading…
Reference in new issue