6 changed files with 33 additions and 45 deletions
@ -1,12 +1,20 @@ |
|||||||
<script lang="ts"> |
<script lang="ts"> |
||||||
import Article from '$lib/Article.svelte'; |
import Article from '$lib/Article.svelte'; |
||||||
|
import { ndk } from '$lib/ndk'; |
||||||
|
import { TextPlaceholder } from 'flowbite-svelte'; |
||||||
import type { PageData } from './$types'; |
import type { PageData } from './$types'; |
||||||
|
|
||||||
export let data: PageData; |
export let data: PageData; |
||||||
|
|
||||||
$: ({ event } = data); |
const getIndexEvent = (d: string) => { |
||||||
|
return $ndk.fetchEvent({ '#d': [d] }); |
||||||
|
}; |
||||||
</script> |
</script> |
||||||
|
|
||||||
<main> |
<main> |
||||||
<Article {event} /> |
{#await getIndexEvent(data.event.d)} |
||||||
|
<TextPlaceholder size='xxl' /> |
||||||
|
{:then index} |
||||||
|
<Article {index} /> |
||||||
|
{/await} |
||||||
</main> |
</main> |
||||||
|
|||||||
@ -1,32 +1,11 @@ |
|||||||
import { getNdkInstance } from "$lib/ndk"; |
import type { PageLoad } from './$types'; |
||||||
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; |
|
||||||
|
|
||||||
export const load: PageLoad = async ({ params }) => { |
export const load: PageLoad = async ({ params }) => { |
||||||
const ndk = getNdkInstance(); |
|
||||||
const { tag } = params; |
const { tag } = params; |
||||||
|
|
||||||
let events: Set<NDKEvent> = new Set(); |
return { |
||||||
let event: NDKEvent | null | undefined; |
event: { |
||||||
|
d: tag, |
||||||
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 }; |
|
||||||
}; |
}; |
||||||
|
|||||||
Loading…
Reference in new issue