Something went wrong. Try again.
a tool for shared writing and social publishing
Something went wrong. Try again.
813 B · 29 lines
TSX
at main
123456789101112131415161718192021222324252627282930"use client";import { useUIState, type EditorOpenPage } from "src/useUIState";import { useEffect } from "react";import { usePathname } from "next/navigation";
const routeOpenPages = new Map<string, EditorOpenPage[]>();let previousPathname = null as null | string;export const RouteUIStateManager = () => { const pathname = usePathname(); useEffect(() => { routeOpenPages.set( previousPathname || pathname, useUIState.getState().openPages, ); previousPathname = pathname;
// Restore open pages for new route if we have them const savedOpenPages = routeOpenPages.get(pathname) || [];
useUIState.setState({ focusedEntity: null, selectedBlocks: [], openPages: savedOpenPages, lastUsedHighlight: "1", }); }, [pathname]);
return null;};