From a34a05e5b59f128dc2c0f6b129ea0d7486808e58 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 1 Jun 2026 19:11:29 +0300 Subject: [PATCH] persist pinned sections expanded state in sidebar --- components/home-components/AppSidebar.tsx | 54 +++++++++++++++++++++-- 1 file changed, 50 insertions(+), 4 deletions(-) diff --git a/components/home-components/AppSidebar.tsx b/components/home-components/AppSidebar.tsx index d0f2855..f02c9cf 100644 --- a/components/home-components/AppSidebar.tsx +++ b/components/home-components/AppSidebar.tsx @@ -103,6 +103,44 @@ const noteTitleSchema = z type PreferredAction = "note" | "DiffNote"; const STORAGE_KEY = "notevo_create_note_action"; +const PINNED_NOTES_EXPANDED_STORAGE_KEY = + "notevo_sidebar_pinned_notes_expanded"; +const PINNED_UPLOADS_EXPANDED_STORAGE_KEY = + "notevo_sidebar_pinned_uploads_expanded"; + +function useStoredExpandedState(storageKey: string, defaultValue = true) { + const [isExpanded, setIsExpanded] = useState(defaultValue); + + useEffect(() => { + if (typeof window === "undefined") return; + + const savedValue = window.localStorage.getItem(storageKey); + if (savedValue === "true") { + setIsExpanded(true); + } else if (savedValue === "false") { + setIsExpanded(false); + } + }, [storageKey]); + + const setStoredExpanded = useCallback( + (nextValue: boolean | ((currentValue: boolean) => boolean)) => { + setIsExpanded((currentValue) => { + const resolvedValue = + typeof nextValue === "function" ? nextValue(currentValue) : nextValue; + + if (typeof window !== "undefined") { + window.localStorage.setItem(storageKey, String(resolvedValue)); + } + + return resolvedValue; + }); + }, + [storageKey], + ); + + return [isExpanded, setStoredExpanded] as const; +} + const SidebarHeaderSection = memo(function SidebarHeaderSection({ getWorkingSpaces, handleCreateNote, @@ -465,6 +503,10 @@ const PinnedNotesList = memo(function PinnedNotesList({ status, loadMore, }: PinnedNotesListProps) { + const [isExpanded, setIsExpanded] = useStoredExpandedState( + PINNED_NOTES_EXPANDED_STORAGE_KEY, + ); + if (status === "LoadingFirstPage") { return ( @@ -497,14 +539,14 @@ const PinnedNotesList = memo(function PinnedNotesList({ if (favoriteNotes.length === 0) { return null; } - const [isExpanded, setIsExpanded] = useState(true); + return (