From 6a387675c0b49a0c28a5deeb30290416a41da0d1 Mon Sep 17 00:00:00 2001 From: sid597 Date: Mon, 25 May 2026 12:00:29 +0530 Subject: [PATCH] ENG-1670: Fix global left sidebar fold toggle Remove the redundant Folded checkbox from settings (chevron is the single source of truth), default the global section to open when children are present, and fix the folded semantic so a persisted Folded block now actually means closed. --- apps/roam/src/components/LeftSidebarView.tsx | 76 ++++++++++--------- .../settings/LeftSidebarGlobalSettings.tsx | 16 +--- 2 files changed, 43 insertions(+), 49 deletions(-) diff --git a/apps/roam/src/components/LeftSidebarView.tsx b/apps/roam/src/components/LeftSidebarView.tsx index 684a45f0a..c35c31a88 100644 --- a/apps/roam/src/components/LeftSidebarView.tsx +++ b/apps/roam/src/components/LeftSidebarView.tsx @@ -132,15 +132,13 @@ const toggleFoldedState = async ({ setIsOpen, folded, parentUid, - isGlobal, sectionIndex, }: { isOpen: boolean; setIsOpen: Dispatch>; folded: { uid?: string; value: boolean }; parentUid: string; - isGlobal?: boolean; - sectionIndex?: number; + sectionIndex: number; }) => { const newFolded = !isOpen; setIsOpen(newFolded); @@ -166,27 +164,16 @@ const toggleFoldedState = async ({ refreshConfigTree(); - if (isGlobal) { - setGlobalSetting( - [ - GLOBAL_KEYS.leftSidebar, - LEFT_SIDEBAR_KEYS.settings, - LEFT_SIDEBAR_SETTINGS_KEYS.folded, - ], - newFolded, - ); - } else if (sectionIndex !== undefined) { - const sections = [...getPersonalSettings()[PERSONAL_KEYS.leftSidebar]]; - if (sections[sectionIndex]) { - sections[sectionIndex] = { - ...sections[sectionIndex], - Settings: { - ...sections[sectionIndex].Settings, - Folded: newFolded, - }, - }; - setPersonalSetting([PERSONAL_KEYS.leftSidebar], sections); - } + const sections = [...getPersonalSettings()[PERSONAL_KEYS.leftSidebar]]; + if (sections[sectionIndex]) { + sections[sectionIndex] = { + ...sections[sectionIndex], + Settings: { + ...sections[sectionIndex].Settings, + Folded: newFolded, + }, + }; + setPersonalSetting([PERSONAL_KEYS.leftSidebar], sections); } }; @@ -459,9 +446,7 @@ const GlobalSection = ({ onGlobalChildrenReorder: (oldIndex: number, newIndex: number) => void; onloadArgs: OnloadArgs; }) => { - const [isOpen, setIsOpen] = useState( - !!config.settings?.folded.value, - ); + const [isOpen, setIsOpen] = useState(!config.settings?.folded.value); const isTogglingRef = useRef(false); if (!config.children?.length) return null; const isCollapsable = config.settings?.collapsable.value; @@ -471,13 +456,36 @@ const GlobalSection = ({ if (isTogglingRef.current) return; isTogglingRef.current = true; try { - await toggleFoldedState({ - isOpen, - setIsOpen, - folded: config.settings.folded, - parentUid: config.settings.uid, - isGlobal: true, - }); + const settings = config.settings; + const nextIsOpen = !isOpen; + setIsOpen(nextIsOpen); + if (nextIsOpen) { + const children = getBasicTreeByParentUid(settings.uid); + await Promise.all( + children + .filter((c) => c.text === "Folded") + .map((c) => deleteBlock(c.uid)), + ); + settings.folded.uid = undefined; + settings.folded.value = false; + } else { + const newUid = window.roamAlphaAPI.util.generateUID(); + await createBlock({ + parentUid: settings.uid, + node: { text: "Folded", uid: newUid }, + }); + settings.folded.uid = newUid; + settings.folded.value = true; + } + refreshConfigTree(); + setGlobalSetting( + [ + GLOBAL_KEYS.leftSidebar, + LEFT_SIDEBAR_KEYS.settings, + LEFT_SIDEBAR_SETTINGS_KEYS.folded, + ], + !nextIsOpen, + ); } finally { isTogglingRef.current = false; } diff --git a/apps/roam/src/components/settings/LeftSidebarGlobalSettings.tsx b/apps/roam/src/components/settings/LeftSidebarGlobalSettings.tsx index 1666bb0d9..28cb045b2 100644 --- a/apps/roam/src/components/settings/LeftSidebarGlobalSettings.tsx +++ b/apps/roam/src/components/settings/LeftSidebarGlobalSettings.tsx @@ -295,20 +295,6 @@ const LeftSidebarGlobalSectionsContent = ({ border: "1px solid rgba(51, 51, 51, 0.2)", }} > -