Skip to content

Commit 92d3c56

Browse files
authored
ENG-1670: Fix global left sidebar fold toggle (#1080)
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.
1 parent cfc1b9d commit 92d3c56

2 files changed

Lines changed: 43 additions & 49 deletions

File tree

apps/roam/src/components/LeftSidebarView.tsx

Lines changed: 42 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -132,15 +132,13 @@ const toggleFoldedState = async ({
132132
setIsOpen,
133133
folded,
134134
parentUid,
135-
isGlobal,
136135
sectionIndex,
137136
}: {
138137
isOpen: boolean;
139138
setIsOpen: Dispatch<SetStateAction<boolean>>;
140139
folded: { uid?: string; value: boolean };
141140
parentUid: string;
142-
isGlobal?: boolean;
143-
sectionIndex?: number;
141+
sectionIndex: number;
144142
}) => {
145143
const newFolded = !isOpen;
146144
setIsOpen(newFolded);
@@ -166,27 +164,16 @@ const toggleFoldedState = async ({
166164

167165
refreshConfigTree();
168166

169-
if (isGlobal) {
170-
setGlobalSetting(
171-
[
172-
GLOBAL_KEYS.leftSidebar,
173-
LEFT_SIDEBAR_KEYS.settings,
174-
LEFT_SIDEBAR_SETTINGS_KEYS.folded,
175-
],
176-
newFolded,
177-
);
178-
} else if (sectionIndex !== undefined) {
179-
const sections = [...getPersonalSettings()[PERSONAL_KEYS.leftSidebar]];
180-
if (sections[sectionIndex]) {
181-
sections[sectionIndex] = {
182-
...sections[sectionIndex],
183-
Settings: {
184-
...sections[sectionIndex].Settings,
185-
Folded: newFolded,
186-
},
187-
};
188-
setPersonalSetting([PERSONAL_KEYS.leftSidebar], sections);
189-
}
167+
const sections = [...getPersonalSettings()[PERSONAL_KEYS.leftSidebar]];
168+
if (sections[sectionIndex]) {
169+
sections[sectionIndex] = {
170+
...sections[sectionIndex],
171+
Settings: {
172+
...sections[sectionIndex].Settings,
173+
Folded: newFolded,
174+
},
175+
};
176+
setPersonalSetting([PERSONAL_KEYS.leftSidebar], sections);
190177
}
191178
};
192179

@@ -459,9 +446,7 @@ const GlobalSection = ({
459446
onGlobalChildrenReorder: (oldIndex: number, newIndex: number) => void;
460447
onloadArgs: OnloadArgs;
461448
}) => {
462-
const [isOpen, setIsOpen] = useState<boolean>(
463-
!!config.settings?.folded.value,
464-
);
449+
const [isOpen, setIsOpen] = useState<boolean>(!config.settings?.folded.value);
465450
const isTogglingRef = useRef(false);
466451
if (!config.children?.length) return null;
467452
const isCollapsable = config.settings?.collapsable.value;
@@ -471,13 +456,36 @@ const GlobalSection = ({
471456
if (isTogglingRef.current) return;
472457
isTogglingRef.current = true;
473458
try {
474-
await toggleFoldedState({
475-
isOpen,
476-
setIsOpen,
477-
folded: config.settings.folded,
478-
parentUid: config.settings.uid,
479-
isGlobal: true,
480-
});
459+
const settings = config.settings;
460+
const nextIsOpen = !isOpen;
461+
setIsOpen(nextIsOpen);
462+
if (nextIsOpen) {
463+
const children = getBasicTreeByParentUid(settings.uid);
464+
await Promise.all(
465+
children
466+
.filter((c) => c.text === "Folded")
467+
.map((c) => deleteBlock(c.uid)),
468+
);
469+
settings.folded.uid = undefined;
470+
settings.folded.value = false;
471+
} else {
472+
const newUid = window.roamAlphaAPI.util.generateUID();
473+
await createBlock({
474+
parentUid: settings.uid,
475+
node: { text: "Folded", uid: newUid },
476+
});
477+
settings.folded.uid = newUid;
478+
settings.folded.value = true;
479+
}
480+
refreshConfigTree();
481+
setGlobalSetting(
482+
[
483+
GLOBAL_KEYS.leftSidebar,
484+
LEFT_SIDEBAR_KEYS.settings,
485+
LEFT_SIDEBAR_SETTINGS_KEYS.folded,
486+
],
487+
!nextIsOpen,
488+
);
481489
} finally {
482490
isTogglingRef.current = false;
483491
}

apps/roam/src/components/settings/LeftSidebarGlobalSettings.tsx

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -295,20 +295,6 @@ const LeftSidebarGlobalSectionsContent = ({
295295
border: "1px solid rgba(51, 51, 51, 0.2)",
296296
}}
297297
>
298-
<GlobalFlagPanel
299-
title="Folded"
300-
description="If children are present, start with global section collapsed in left sidebar"
301-
settingKeys={[
302-
GLOBAL_KEYS.leftSidebar,
303-
LEFT_SIDEBAR_KEYS.settings,
304-
LEFT_SIDEBAR_SETTINGS_KEYS.folded,
305-
]}
306-
initialValue={globalSection.settings?.folded?.value || false}
307-
order={0}
308-
uid={globalSection.settings?.folded?.uid || ""}
309-
parentUid={globalSection.settings?.uid || ""}
310-
disabled={!globalSection.children?.length}
311-
/>
312298
<GlobalFlagPanel
313299
title="Collapsable"
314300
description="Make global section collapsable"
@@ -318,7 +304,7 @@ const LeftSidebarGlobalSectionsContent = ({
318304
LEFT_SIDEBAR_SETTINGS_KEYS.collapsable,
319305
]}
320306
initialValue={globalSection.settings?.collapsable?.value || false}
321-
order={1}
307+
order={0}
322308
uid={globalSection.settings?.collapsable?.uid || ""}
323309
parentUid={globalSection.settings?.uid || ""}
324310
/>

0 commit comments

Comments
 (0)