10 changed files with 67 additions and 77 deletions
@ -1,12 +0,0 @@ |
|||||||
<script lang="ts"> |
|
||||||
import Article from '$lib/components/Article.svelte'; |
|
||||||
import type { PageData } from './$types'; |
|
||||||
|
|
||||||
export let data: PageData; |
|
||||||
|
|
||||||
let { event } = data; |
|
||||||
</script> |
|
||||||
|
|
||||||
<main> |
|
||||||
<Article {event} /> |
|
||||||
</main> |
|
||||||
@ -1,26 +0,0 @@ |
|||||||
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 }) => { |
|
||||||
const ndk = getNdkInstance(); |
|
||||||
const { id } = params; |
|
||||||
|
|
||||||
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,20 +0,0 @@ |
|||||||
<script lang="ts"> |
|
||||||
import Article from '$lib/components/Article.svelte'; |
|
||||||
import { ndk } from '$lib/ndk'; |
|
||||||
import { TextPlaceholder } from 'flowbite-svelte'; |
|
||||||
import type { PageData } from './$types'; |
|
||||||
|
|
||||||
export let data: PageData; |
|
||||||
|
|
||||||
const getIndexEvent = (d: string) => { |
|
||||||
return $ndk.fetchEvent({ '#d': [d] }); |
|
||||||
}; |
|
||||||
</script> |
|
||||||
|
|
||||||
<main> |
|
||||||
{#await getIndexEvent(data.event.d)} |
|
||||||
<TextPlaceholder size='xxl' /> |
|
||||||
{:then index} |
|
||||||
<Article {index} /> |
|
||||||
{/await} |
|
||||||
</main> |
|
||||||
@ -1,11 +0,0 @@ |
|||||||
import type { PageLoad } from './$types'; |
|
||||||
|
|
||||||
export const load: PageLoad = async ({ params }) => { |
|
||||||
const { tag } = params; |
|
||||||
|
|
||||||
return { |
|
||||||
event: { |
|
||||||
d: tag, |
|
||||||
} |
|
||||||
}; |
|
||||||
}; |
|
||||||
@ -0,0 +1,42 @@ |
|||||||
|
<script lang="ts"> |
||||||
|
import { page } from '$app/stores'; |
||||||
|
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'; |
||||||
|
|
||||||
|
const id = $page.url.searchParams.get('id'); |
||||||
|
const dTag = $page.url.searchParams.get('d'); |
||||||
|
|
||||||
|
let event: NDKEvent | null | undefined; |
||||||
|
|
||||||
|
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> |
||||||
|
|
||||||
|
<main> |
||||||
|
{#await event} |
||||||
|
<TextPlaceholder size='xxl' /> |
||||||
|
{:then ev} |
||||||
|
<Article index={ev} /> |
||||||
|
{/await} |
||||||
|
</main> |
||||||
Loading…
Reference in new issue