refactor(spa): detail-route nur noch snapshot-pfad
Runtime-fallback (loadPost + LoadingOrError + PostView) entfernt. Detail-seite rendert jetzt ausschliesslich aus dem snapshot. Imports und state, die nur fuer den fallback gebraucht wurden, sind weg. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
a57ae1e8bf
commit
0ec72f9426
|
|
@ -1,36 +1,17 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import type { NostrEvent } from '$lib/nostr/loaders'
|
import type { NostrEvent } from '$lib/nostr/loaders'
|
||||||
import { loadPost } from '$lib/nostr/loaders'
|
|
||||||
import { AUTHOR_PUBKEY_HEX } from '$lib/nostr/config'
|
|
||||||
import { buildHablaLink } from '$lib/nostr/naddr'
|
|
||||||
import PostView from '$lib/components/PostView.svelte'
|
|
||||||
import LoadingOrError from '$lib/components/LoadingOrError.svelte'
|
|
||||||
import Reactions from '$lib/components/Reactions.svelte'
|
import Reactions from '$lib/components/Reactions.svelte'
|
||||||
import ReplyList from '$lib/components/ReplyList.svelte'
|
import ReplyList from '$lib/components/ReplyList.svelte'
|
||||||
import ReplyComposer from '$lib/components/ReplyComposer.svelte'
|
import ReplyComposer from '$lib/components/ReplyComposer.svelte'
|
||||||
import ExternalClientLinks from '$lib/components/ExternalClientLinks.svelte'
|
import ExternalClientLinks from '$lib/components/ExternalClientLinks.svelte'
|
||||||
import { renderMarkdown } from '$lib/render/markdown'
|
import { renderMarkdown } from '$lib/render/markdown'
|
||||||
import { t } from '$lib/i18n'
|
import { t } from '$lib/i18n'
|
||||||
import { get } from 'svelte/store'
|
|
||||||
import { onMount } from 'svelte'
|
|
||||||
import type { SignedEvent } from '$lib/nostr/signer'
|
import type { SignedEvent } from '$lib/nostr/signer'
|
||||||
|
|
||||||
let { data } = $props()
|
let { data } = $props()
|
||||||
const dtag = $derived(data.dtag)
|
const dtag = $derived(data.dtag)
|
||||||
const snapshot = $derived(data.snapshot)
|
const snapshot = $derived(data.snapshot)
|
||||||
|
|
||||||
let post: NostrEvent | null = $state(null)
|
|
||||||
let loading = $state(false)
|
|
||||||
let error: string | null = $state(null)
|
|
||||||
|
|
||||||
const hablaLink = $derived(
|
|
||||||
buildHablaLink({
|
|
||||||
pubkey: AUTHOR_PUBKEY_HEX,
|
|
||||||
kind: 30023,
|
|
||||||
identifier: dtag,
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
|
|
||||||
const siteUrl = '__SITE_URL__'
|
const siteUrl = '__SITE_URL__'
|
||||||
const canonical = $derived(`${siteUrl}/${snapshot?.slug ?? dtag}/`)
|
const canonical = $derived(`${siteUrl}/${snapshot?.slug ?? dtag}/`)
|
||||||
const ogImage = $derived(
|
const ogImage = $derived(
|
||||||
|
|
@ -43,25 +24,6 @@
|
||||||
snapshot ? renderMarkdown(snapshot.content_markdown) : '',
|
snapshot ? renderMarkdown(snapshot.content_markdown) : '',
|
||||||
)
|
)
|
||||||
|
|
||||||
onMount(() => {
|
|
||||||
if (snapshot) return
|
|
||||||
loading = true
|
|
||||||
const currentDtag = dtag
|
|
||||||
loadPost(currentDtag)
|
|
||||||
.then((p) => {
|
|
||||||
if (currentDtag !== dtag) return
|
|
||||||
if (!p) error = get(t)('post.not_found', { values: { slug: currentDtag } })
|
|
||||||
else post = p
|
|
||||||
})
|
|
||||||
.catch((e) => {
|
|
||||||
if (currentDtag !== dtag) return
|
|
||||||
error = e instanceof Error ? e.message : get(t)('post.unknown_error')
|
|
||||||
})
|
|
||||||
.finally(() => {
|
|
||||||
if (currentDtag === dtag) loading = false
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
let optimisticReplies: NostrEvent[] = $state([])
|
let optimisticReplies: NostrEvent[] = $state([])
|
||||||
function handlePublished(signed: SignedEvent) {
|
function handlePublished(signed: SignedEvent) {
|
||||||
optimisticReplies = [...optimisticReplies, signed as unknown as NostrEvent]
|
optimisticReplies = [...optimisticReplies, signed as unknown as NostrEvent]
|
||||||
|
|
@ -152,11 +114,6 @@
|
||||||
<ReplyComposer dtag={snapshot.slug} eventId={snapshot.event_id} onPublished={handlePublished} />
|
<ReplyComposer dtag={snapshot.slug} eventId={snapshot.event_id} onPublished={handlePublished} />
|
||||||
<ReplyList dtag={snapshot.slug} optimistic={optimisticReplies} />
|
<ReplyList dtag={snapshot.slug} optimistic={optimisticReplies} />
|
||||||
</article>
|
</article>
|
||||||
{:else}
|
|
||||||
<LoadingOrError {loading} {error} {hablaLink} />
|
|
||||||
{#if post}
|
|
||||||
<PostView event={post} />
|
|
||||||
{/if}
|
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue