Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 42 additions & 34 deletions apps/roam/src/components/LeftSidebarView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -132,15 +132,13 @@ const toggleFoldedState = async ({
setIsOpen,
folded,
parentUid,
isGlobal,
sectionIndex,
}: {
isOpen: boolean;
setIsOpen: Dispatch<SetStateAction<boolean>>;
folded: { uid?: string; value: boolean };
parentUid: string;
isGlobal?: boolean;
sectionIndex?: number;
sectionIndex: number;
}) => {
const newFolded = !isOpen;
setIsOpen(newFolded);
Expand All @@ -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);
}
};

Expand Down Expand Up @@ -459,9 +446,7 @@ const GlobalSection = ({
onGlobalChildrenReorder: (oldIndex: number, newIndex: number) => void;
onloadArgs: OnloadArgs;
}) => {
const [isOpen, setIsOpen] = useState<boolean>(
!!config.settings?.folded.value,
);
const [isOpen, setIsOpen] = useState<boolean>(!config.settings?.folded.value);
const isTogglingRef = useRef(false);
if (!config.children?.length) return null;
const isCollapsable = config.settings?.collapsable.value;
Expand All @@ -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;
}
Expand Down
16 changes: 1 addition & 15 deletions apps/roam/src/components/settings/LeftSidebarGlobalSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -295,20 +295,6 @@ const LeftSidebarGlobalSectionsContent = ({
border: "1px solid rgba(51, 51, 51, 0.2)",
}}
>
<GlobalFlagPanel
title="Folded"
description="If children are present, start with global section collapsed in left sidebar"
settingKeys={[
GLOBAL_KEYS.leftSidebar,
LEFT_SIDEBAR_KEYS.settings,
LEFT_SIDEBAR_SETTINGS_KEYS.folded,
]}
initialValue={globalSection.settings?.folded?.value || false}
order={0}
uid={globalSection.settings?.folded?.uid || ""}
parentUid={globalSection.settings?.uid || ""}
disabled={!globalSection.children?.length}
/>
<GlobalFlagPanel
title="Collapsable"
description="Make global section collapsable"
Expand All @@ -318,7 +304,7 @@ const LeftSidebarGlobalSectionsContent = ({
LEFT_SIDEBAR_SETTINGS_KEYS.collapsable,
]}
initialValue={globalSection.settings?.collapsable?.value || false}
order={1}
order={0}
uid={globalSection.settings?.collapsable?.uid || ""}
parentUid={globalSection.settings?.uid || ""}
/>
Expand Down
Loading