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