6 changed files with 33 additions and 45 deletions
@ -1,12 +1,20 @@
@@ -1,12 +1,20 @@
|
||||
<script lang="ts"> |
||||
import Article from '$lib/Article.svelte'; |
||||
import { ndk } from '$lib/ndk'; |
||||
import { TextPlaceholder } from 'flowbite-svelte'; |
||||
import type { PageData } from './$types'; |
||||
|
||||
export let data: PageData; |
||||
|
||||
$: ({ event } = data); |
||||
const getIndexEvent = (d: string) => { |
||||
return $ndk.fetchEvent({ '#d': [d] }); |
||||
}; |
||||
</script> |
||||
|
||||
<main> |
||||
<Article {event} /> |
||||
{#await getIndexEvent(data.event.d)} |
||||
<TextPlaceholder size='xxl' /> |
||||
{:then index} |
||||
<Article {index} /> |
||||
{/await} |
||||
</main> |
||||
|
||||
@ -1,32 +1,11 @@
@@ -1,32 +1,11 @@
|
||||
import { getNdkInstance } from "$lib/ndk"; |
||||
import type { NDKEvent, NDKKind } from "@nostr-dev-kit/ndk"; |
||||
import { error } from "@sveltejs/kit"; |
||||
import type { PageLoad } from "./$types"; |
||||
|
||||
// MichaelJ - 23 July 2024 - Disable server-side rendering so that the load function can use the
|
||||
// browser's local storage to retrieve saved relays and the cache adapter for the NDK instance.
|
||||
export const ssr = false; |
||||
import type { PageLoad } from './$types'; |
||||
|
||||
export const load: PageLoad = async ({ params }) => { |
||||
const ndk = getNdkInstance(); |
||||
const { tag } = params; |
||||
|
||||
let events: Set<NDKEvent> = new Set(); |
||||
let event: NDKEvent | null | undefined; |
||||
|
||||
try { |
||||
events = await ndk.fetchEvents({ |
||||
kinds: [30040 as NDKKind], |
||||
'#d': [tag], |
||||
}); |
||||
event = events.values().next().value; |
||||
} catch (err) { |
||||
console.error(err); |
||||
} |
||||
|
||||
if (events.size === 0) { |
||||
error(404, 'No events found with the given d tag.'); |
||||
} |
||||
|
||||
return { event }; |
||||
return { |
||||
event: { |
||||
d: tag, |
||||
} |
||||
}; |
||||
}; |
||||
|
||||
Loading…
Reference in new issue