From 125052f4c9bb4af0097c761341166d053789471a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20G=C3=B3mez?= Date: Sun, 21 Dec 2025 22:47:24 +0100 Subject: [PATCH] fix: spellbook preview or direct behavior --- src/components/SpellbookDropdown.tsx | 12 +++++-- src/components/pages/SpellbookPage.tsx | 43 ++++++++++++++++++++------ 2 files changed, 43 insertions(+), 12 deletions(-) diff --git a/src/components/SpellbookDropdown.tsx b/src/components/SpellbookDropdown.tsx index 0394a43..5176d64 100644 --- a/src/components/SpellbookDropdown.tsx +++ b/src/components/SpellbookDropdown.tsx @@ -259,8 +259,14 @@ export function SpellbookDropdown() { }; const handleCloseSpellbook = () => { - clearActiveSpellbook(); - toast.info("Spellbook closed"); + if (isTemporary) { + discardTemporary(); + navigate("/", { replace: true }); + toast.info("Returned to your dashboard"); + } else { + clearActiveSpellbook(); + toast.info("Spellbook closed"); + } }; const itemClass = @@ -287,7 +293,7 @@ export function SpellbookDropdown() { - + {activeSpellbook ? activeSpellbook.title : "grimoire"} diff --git a/src/components/pages/SpellbookPage.tsx b/src/components/pages/SpellbookPage.tsx index 40da38b..d0008a6 100644 --- a/src/components/pages/SpellbookPage.tsx +++ b/src/components/pages/SpellbookPage.tsx @@ -28,9 +28,15 @@ export default function SpellbookPage() { const [isResolving, setIsResolving] = useState(false); const [hasLoadedSpellbook, setHasLoadedSpellbook] = useState(false); + // Reset loading state when params change + useEffect(() => { + setHasLoadedSpellbook(false); + }, [actor, identifier]); + + const isPreviewPath = location.pathname.startsWith("/preview/"); // Determine if we should show the preview banner - // In SpellbookPage, we always show it if we have loaded a spellbook temporarily - const showBanner = isTemporary && hasLoadedSpellbook; + // In SpellbookPage, we only show it if we have loaded a spellbook temporarily AND we are in a preview route + const showBanner = isTemporary && hasLoadedSpellbook && isPreviewPath; // 1. Resolve actor to pubkey useEffect(() => { @@ -95,24 +101,33 @@ export default function SpellbookPage() { useEffect(() => { if (spellbookEvent && !hasLoadedSpellbook) { try { - const parsed = parseSpellbook(spellbookEvent as SpellbookEvent); - switchToTemporary(parsed); - setHasLoadedSpellbook(true); + const parsedSpellbook = parseSpellbook(spellbookEvent as SpellbookEvent); - const isPreviewPath = location.pathname.startsWith("/preview/"); + const isPreviewPath = location.pathname.startsWith("/preview/"); // Check if it's a preview route + if (isPreviewPath) { - toast.info(`Previewing spellbook: ${parsed.title}`, { + // If it's a preview route, load into temporary state and show the banner + switchToTemporary(parsedSpellbook); + toast.info(`Previewing spellbook: ${parsedSpellbook.title}`, { description: "You are in a temporary session. Apply to keep this spellbook.", }); + } else { + // If it's not a preview route, just load into temporary state. + // This bypasses the banner but doesn't overwrite the persistent dashboard. + // Navigating to / (Home) will restore the user's dashboard. + switchToTemporary(parsedSpellbook); } - + + setHasLoadedSpellbook(true); // Mark as loaded, regardless of preview or direct load + } catch (e) { console.error("Failed to parse spellbook:", e); toast.error("Failed to load spellbook"); + setHasLoadedSpellbook(true); // Ensure we don't re-attempt on error } } - }, [spellbookEvent, hasLoadedSpellbook, switchToTemporary, location.pathname]); + }, [spellbookEvent, hasLoadedSpellbook, switchToTemporary, applyTemporaryToPersistent, location.pathname]); // Cleanup when leaving the page (unmounting) // But wait, if we navigate to /, we want to discard. @@ -264,7 +279,17 @@ export default function SpellbookPage() { {/* Main Content */}
+ {!hasLoadedSpellbook && !resolutionError ? ( +
+ +
+

Loading Spellbook...

+

Fetching from the relays

+
+
+ ) : ( + )}
);