a tool for shared writing and social publishing
at main 808 B view raw
1"use client"; 2import { useUIState } from "src/useUIState"; 3import { useEffect } from "react"; 4import { usePathname } from "next/navigation"; 5 6const routeOpenPages = new Map<string, string[]>(); 7let previousPathname = null as null | string; 8export const RouteUIStateManager = () => { 9 const pathname = usePathname(); 10 useEffect(() => { 11 routeOpenPages.set( 12 previousPathname || pathname, 13 useUIState.getState().openPages, 14 ); 15 previousPathname = pathname; 16 17 // Restore open pages for new route if we have them 18 const savedOpenPages = routeOpenPages.get(pathname) || []; 19 20 useUIState.setState({ 21 focusedEntity: null, 22 selectedBlocks: [], 23 foldedBlocks: [], 24 openPages: savedOpenPages, 25 lastUsedHighlight: "1", 26 }); 27 }, [pathname]); 28 29 return null; 30};