diff --git a/src/lib/modules/profiles/ProfilePage.svelte b/src/lib/modules/profiles/ProfilePage.svelte index 1fc2c0c..c15fd48 100644 --- a/src/lib/modules/profiles/ProfilePage.svelte +++ b/src/lib/modules/profiles/ProfilePage.svelte @@ -12,6 +12,7 @@ import { sessionManager } from '../../services/auth/session-manager.js'; import { onMount } from 'svelte'; import { page } from '$app/stores'; + import { goto } from '$app/navigation'; import { nip19 } from 'nostr-tools'; import type { NostrEvent } from '../../types/nostr.js'; import { KIND } from '../../types/kind-lookup.js'; @@ -32,6 +33,48 @@ let nip05Validations = $state>({}); // null = checking, true = valid, false = invalid // Compute pubkey from route params let profilePubkey = $derived.by(() => decodePubkey($page.params.pubkey)); + + // Initialize activeTab from URL parameter + function getTabFromUrl(): 'pins' | 'notifications' | 'interactions' | 'wall' { + const tabParam = $page.url.searchParams.get('tab'); + const validTabs: Array<'pins' | 'notifications' | 'interactions' | 'wall'> = ['pins', 'notifications', 'interactions', 'wall']; + if (tabParam && validTabs.includes(tabParam as any)) { + return tabParam as 'pins' | 'notifications' | 'interactions' | 'wall'; + } + return 'pins'; // Default + } + + // Update activeTab when URL changes + $effect(() => { + const urlTab = getTabFromUrl(); + if (urlTab !== activeTab) { + activeTab = urlTab; + // Load data for the tab if needed + if (activeTab === 'wall' && profileEvent && wallComments.length === 0 && !loadingWall) { + loadWallComments(profileEvent.id); + } + } + }); + + // Function to change tab and update URL + async function setActiveTab(tab: 'pins' | 'notifications' | 'interactions' | 'wall') { + activeTab = tab; + const url = new URL($page.url); + url.searchParams.set('tab', tab); + goto(url.pathname + url.search, { replaceState: true, noScroll: true }); + + // Handle tab-specific logic + if (tab === 'wall') { + // Load profile event if not loaded yet + if (!profileEvent && profilePubkey) { + await loadProfileEvent(profilePubkey); + } + // Load wall comments if profile event is available and not already loaded + if (profileEvent && wallComments.length === 0 && !loadingWall) { + await loadWallComments(profileEvent.id); + } + } + } // Cache for NIP-05 validation results (nip05+pubkey -> result) // This prevents re-validating the same NIP-05 address repeatedly @@ -402,6 +445,8 @@ onMount(async () => { await nostrClient.initialize(); + // Initialize tab from URL + activeTab = getTabFromUrl(); // Load profile after initialization if ($page.params.pubkey) { loadProfile(); @@ -775,37 +820,27 @@
{#if isOwnProfile} {:else if currentUserPubkey && currentUserPubkey !== profilePubkey} @@ -942,7 +971,7 @@