Browse Source

Fixed relay display on About page

master
silberengel 8 months ago
parent
commit
8b6db819dc
  1. 7
      src/lib/ndk.ts
  2. 86
      src/routes/publication/[type]/[identifier]/+page.svelte

7
src/lib/ndk.ts

@ -6,7 +6,7 @@ import NDK, {
NDKUser, NDKUser,
NDKEvent, NDKEvent,
} from "@nostr-dev-kit/ndk"; } from "@nostr-dev-kit/ndk";
import { get, writable, type Writable } from "svelte/store"; import { writable, get, type Writable } from "svelte/store";
import { import {
loginStorageKey, loginStorageKey,
} from "./consts.ts"; } from "./consts.ts";
@ -33,6 +33,11 @@ export const outboxRelays = writable<string[]>([]);
export const activeInboxRelays = writable<string[]>([]); export const activeInboxRelays = writable<string[]>([]);
export const activeOutboxRelays = writable<string[]>([]); export const activeOutboxRelays = writable<string[]>([]);
// Subscribe to userStore changes and update ndkSignedIn accordingly
userStore.subscribe((userState) => {
ndkSignedIn.set(userState.signedIn);
});
/** /**
* Custom authentication policy that handles NIP-42 authentication manually * Custom authentication policy that handles NIP-42 authentication manually
* when the default NDK authentication fails * when the default NDK authentication fails

86
src/routes/publication/[type]/[identifier]/+page.svelte

@ -12,41 +12,51 @@
let { data }: PageProps = $props(); let { data }: PageProps = $props();
const indexEvent = createNDKEvent(data.ndk, data.indexEvent); // data.indexEvent can be null from server-side rendering
const publicationTree = new SveltePublicationTree(indexEvent, data.ndk); // We need to handle this case properly
const toc = new TableOfContents( const indexEvent = data.indexEvent ? createNDKEvent(data.ndk, data.indexEvent) : null;
// Only create publication tree if we have a valid index event
const publicationTree = indexEvent ? new SveltePublicationTree(indexEvent, data.ndk) : null;
const toc = indexEvent ? new TableOfContents(
indexEvent.tagAddress(), indexEvent.tagAddress(),
publicationTree, publicationTree!,
page.url.pathname ?? "", page.url.pathname ?? "",
); ) : null;
setContext("publicationTree", publicationTree); setContext("publicationTree", publicationTree);
setContext("toc", toc); setContext("toc", toc);
setContext("asciidoctor", Processor()); setContext("asciidoctor", Processor());
publicationTree.onBookmarkMoved((address) => { // Only set up bookmark handling if we have a valid publication tree
goto(`#${address}`, { if (publicationTree && indexEvent) {
replaceState: true, publicationTree.onBookmarkMoved((address) => {
}); goto(`#${address}`, {
replaceState: true,
// TODO: Extract IndexedDB interaction to a service layer.
// Store bookmark in IndexedDB
const db = indexedDB.open("alexandria", 1);
db.onupgradeneeded = () => {
const objectStore = db.result.createObjectStore("bookmarks", {
keyPath: "key",
}); });
};
db.onsuccess = () => { // TODO: Extract IndexedDB interaction to a service layer.
const transaction = db.result.transaction(["bookmarks"], "readwrite"); // Store bookmark in IndexedDB
const store = transaction.objectStore("bookmarks"); const db = indexedDB.open("alexandria", 1);
const bookmarkKey = `${indexEvent.tagAddress()}`; db.onupgradeneeded = () => {
store.put({ key: bookmarkKey, address }); const objectStore = db.result.createObjectStore("bookmarks", {
}; keyPath: "key",
}); });
};
db.onsuccess = () => {
const transaction = db.result.transaction(["bookmarks"], "readwrite");
const store = transaction.objectStore("bookmarks");
const bookmarkKey = `${indexEvent.tagAddress()}`;
store.put({ key: bookmarkKey, address });
};
});
}
onMount(() => { onMount(() => {
// Only handle bookmarks if we have valid components
if (!publicationTree || !indexEvent) return;
// TODO: Extract IndexedDB interaction to a service layer. // TODO: Extract IndexedDB interaction to a service layer.
// Read bookmark from IndexedDB // Read bookmark from IndexedDB
const db = indexedDB.open("alexandria", 1); const db = indexedDB.open("alexandria", 1);
@ -81,16 +91,24 @@
}); });
</script> </script>
<ArticleNav {#if indexEvent && data.indexEvent}
publicationType={data.publicationType} <ArticleNav
rootId={data.indexEvent.id}
indexEvent={indexEvent}
/>
<main class="publication {data.publicationType}">
<Publication
rootAddress={indexEvent.tagAddress()}
publicationType={data.publicationType} publicationType={data.publicationType}
rootId={data.indexEvent.id}
indexEvent={indexEvent} indexEvent={indexEvent}
/> />
</main>
<main class="publication {data.publicationType}">
<Publication
rootAddress={indexEvent.tagAddress()}
publicationType={data.publicationType}
indexEvent={indexEvent}
/>
</main>
{:else}
<main class="publication">
<div class="flex items-center justify-center min-h-screen">
<p class="text-gray-600 dark:text-gray-400">Loading publication...</p>
</div>
</main>
{/if}
Loading…
Cancel
Save