4 changed files with 42 additions and 9 deletions
@ -1,12 +1,26 @@
@@ -1,12 +1,26 @@
|
||||
import { getNdkInstance, ndk } from '$lib/ndk'; |
||||
import type { NDKEvent } from '@nostr-dev-kit/ndk'; |
||||
import { error } from '@sveltejs/kit'; |
||||
|
||||
// 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 = async ({ params }) => { |
||||
// TODO: Don't rely on browser cache here.
|
||||
const ndk = getNdkInstance(); |
||||
const { id } = params; |
||||
|
||||
// TODO: Add error handling.
|
||||
const event = await ndk.fetchEvent(id); |
||||
let event: NDKEvent | null | undefined; |
||||
|
||||
try { |
||||
event = await ndk.fetchEvent(id); |
||||
} catch (err) { |
||||
console.error(err); |
||||
} |
||||
|
||||
if (!event) { |
||||
error(404, 'No event found with the given ID.'); |
||||
} |
||||
|
||||
return { event }; |
||||
}; |
||||
|
||||
@ -1,13 +1,28 @@
@@ -1,13 +1,28 @@
|
||||
import { getNdkInstance } from "$lib/ndk"; |
||||
import type { NDKEvent } from "@nostr-dev-kit/ndk"; |
||||
import { error } from "@sveltejs/kit"; |
||||
|
||||
// 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 = async ({ params }) => { |
||||
// TODO: Don't rely on browser cache here.
|
||||
const ndk = getNdkInstance(); |
||||
const { tag } = params; |
||||
|
||||
// TODO: Add error handling.
|
||||
const events = await ndk.fetchEvents({ '#d': [tag] }); |
||||
const event = events.values().next().value; |
||||
let events: Set<NDKEvent> = new Set(); |
||||
let event: NDKEvent | null | undefined; |
||||
|
||||
try { |
||||
events = await ndk.fetchEvents({ '#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