Browse Source

corrected my-notes going blank on refresh and showing when no one is logged-in

master
silberengel 7 months ago
parent
commit
0e720f70e8
  1. 2
      src/lib/components/Navigation.svelte
  2. 31
      src/lib/ndk.ts
  3. 37
      src/routes/my-notes/+page.svelte

2
src/lib/components/Navigation.svelte

@ -31,7 +31,9 @@ @@ -31,7 +31,9 @@
<NavLi href="/visualize">Visualize</NavLi>
<NavLi href="/start">Getting Started</NavLi>
<NavLi href="/events">Events</NavLi>
{#if userState.signedIn}
<NavLi href="/my-notes">My Notes</NavLi>
{/if}
<NavLi href="/about">About</NavLi>
<NavLi href="/contact">Contact</NavLi>
<NavLi>

31
src/lib/ndk.ts

@ -91,20 +91,8 @@ function clearPersistentRelaySet(): void { @@ -91,20 +91,8 @@ function clearPersistentRelaySet(): void {
}
}
// Subscribe to userStore changes and update ndkSignedIn accordingly
userStore.subscribe(async (userState) => {
ndkSignedIn.set(userState.signedIn);
// Refresh relay stores when user state changes
const ndk = get(ndkInstance);
if (ndk) {
try {
await refreshRelayStores(ndk);
} catch (error) {
console.warn('[NDK.ts] Failed to refresh relay stores on user state change:', error);
}
}
});
// AI-NOTE: userStore subscription moved to initNdk function to prevent initialization errors
// The subscription will be set up after userStore is properly initialized
/**
* Custom authentication policy that handles NIP-42 authentication manually
@ -655,6 +643,21 @@ export function initNdk(): NDK { @@ -655,6 +643,21 @@ export function initNdk(): NDK {
attemptConnection();
// AI-NOTE: Set up userStore subscription after NDK initialization to prevent initialization errors
userStore.subscribe(async (userState) => {
ndkSignedIn.set(userState.signedIn);
// Refresh relay stores when user state changes
const ndk = get(ndkInstance);
if (ndk) {
try {
await refreshRelayStores(ndk);
} catch (error) {
console.warn('[NDK.ts] Failed to refresh relay stores on user state change:', error);
}
}
});
return ndk;
}

37
src/routes/my-notes/+page.svelte

@ -1,5 +1,6 @@ @@ -1,5 +1,6 @@
<script lang="ts">
import { onMount } from "svelte";
import { goto } from "$app/navigation";
import { userStore } from "$lib/stores/userStore";
import { ndkInstance } from "$lib/ndk";
import type { NDKEvent } from "@nostr-dev-kit/ndk";
@ -9,26 +10,26 @@ @@ -9,26 +10,26 @@
import asciidoctor from "asciidoctor";
import { postProcessAsciidoctorHtml } from "$lib/utils/markup/asciidoctorPostProcessor";
let events: NDKEvent[] = [];
let loading = true;
let error: string | null = null;
let showTags: Record<string, boolean> = {};
let renderedContent: Record<string, string> = {};
let events: NDKEvent[] = $state([]);
let loading = $state(true);
let error: string | null = $state(null);
let showTags: Record<string, boolean> = $state({});
let renderedContent: Record<string, string> = $state({});
// Tag type and tag filter state
const tagTypes = ["t", "title", "m", "w"]; // 'm' is MIME type
let selectedTagTypes: Set<string> = new Set();
let selectedTagTypes: Set<string> = $state(new Set());
let tagTypeLabels: Record<string, string> = {
t: "hashtag",
title: "",
m: "mime",
w: "wiki",
};
let tagFilter: Set<string> = new Set();
let tagFilter: Set<string> = $state(new Set());
// Unique tags by type
let uniqueTagsByType: Record<string, Set<string>> = {};
let allUniqueTags: Set<string> = new Set();
let uniqueTagsByType: Record<string, Set<string>> = $state({});
let allUniqueTags: Set<string> = $state(new Set());
async function fetchMyNotes() {
loading = true;
@ -132,7 +133,7 @@ @@ -132,7 +133,7 @@
}
// Compute which tags to show in the filter
$: tagsToShow = (() => {
let tagsToShow = $derived.by(() => {
if (selectedTagTypes.size === 0) {
return [];
}
@ -143,10 +144,10 @@ @@ -143,10 +144,10 @@
}
}
return Array.from(tags).sort();
})();
});
// Compute filtered events
$: filteredEvents = (() => {
let filteredEvents = $derived.by(() => {
if (selectedTagTypes.size === 0 && tagFilter.size === 0) {
return events;
}
@ -164,7 +165,17 @@ @@ -164,7 +165,17 @@
// Otherwise, event must have at least one of the selected tags
return relevantTags.some((tag) => tagFilter.has(tag[1]));
});
})();
});
// AI-NOTE: Check authentication status immediately and redirect if not logged in
$effect(() => {
const user = get(userStore);
if (!user.signedIn) {
// Redirect to home page if not logged in
goto('/');
return;
}
});
onMount(fetchMyNotes);
</script>

Loading…
Cancel
Save