Skip to content

Commit 3b70e2b

Browse files
committed
ENG-1217: Port section component in left sidebar
1 parent 69a053f commit 3b70e2b

4 files changed

Lines changed: 199 additions & 86 deletions

File tree

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

Lines changed: 47 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React, { useCallback, useEffect, useMemo, useState, memo } from "react";
22
import { Button, ButtonGroup, Collapse } from "@blueprintjs/core";
3-
import FlagPanel from "roamjs-components/components/ConfigPanels/FlagPanel";
3+
import { GlobalFlagPanel } from "~/components/settings/components/BlockPropSettingPanels";
4+
import { setGlobalSetting } from "~/components/settings/utils/accessors";
45
import AutocompleteInput from "roamjs-components/components/AutocompleteInput";
56
import getAllPageNames from "roamjs-components/queries/getAllPageNames";
67
import createBlock from "roamjs-components/writes/createBlock";
@@ -19,6 +20,9 @@ import getPageTitleByPageUid from "roamjs-components/queries/getPageTitleByPageU
1920
import getTextByBlockUid from "roamjs-components/queries/getTextByBlockUid";
2021
import posthog from "posthog-js";
2122

23+
const pagesToUids = (pages: RoamBasicNode[]) => pages.map((p) => p.text);
24+
25+
2226
const PageItem = memo(
2327
({
2428
page,
@@ -160,6 +164,11 @@ const LeftSidebarGlobalSectionsContent = ({
160164
newPages.splice(newIndex, 0, removed);
161165

162166
setPages(newPages);
167+
setGlobalSetting(
168+
["Left sidebar", "Children"],
169+
pagesToUids(newPages),
170+
);
171+
163172

164173
if (childrenUid) {
165174
const order = direction === "down" ? newIndex + 1 : newIndex;
@@ -201,7 +210,13 @@ const LeftSidebarGlobalSectionsContent = ({
201210
children: [],
202211
};
203212

204-
setPages((prev) => [...prev, newPage]);
213+
const updatedPages = [...pages, newPage];
214+
setPages(updatedPages);
215+
setGlobalSetting(
216+
["Left sidebar", "Children"],
217+
pagesToUids(updatedPages),
218+
);
219+
205220
setNewPageInput("");
206221
setAutocompleteKey((prev) => prev + 1);
207222
posthog.capture("Left Sidebar Global Settings: Page Added", {
@@ -219,19 +234,28 @@ const LeftSidebarGlobalSectionsContent = ({
219234
[childrenUid, pages],
220235
);
221236

222-
const removePage = useCallback(async (page: RoamBasicNode) => {
223-
try {
224-
await deleteBlock(page.uid);
225-
setPages((prev) => prev.filter((p) => p.uid !== page.uid));
226-
refreshAndNotify();
227-
} catch (error) {
228-
renderToast({
229-
content: "Failed to remove page",
230-
intent: "danger",
231-
id: "remove-page-error",
232-
});
233-
}
234-
}, []);
237+
const removePage = useCallback(
238+
async (page: RoamBasicNode) => {
239+
try {
240+
await deleteBlock(page.uid);
241+
const updatedPages = pages.filter((p) => p.uid !== page.uid);
242+
setPages(updatedPages);
243+
setGlobalSetting(
244+
["Left sidebar", "Children"],
245+
pagesToUids(updatedPages),
246+
);
247+
248+
refreshAndNotify();
249+
} catch (error) {
250+
renderToast({
251+
content: "Failed to remove page",
252+
intent: "danger",
253+
id: "remove-page-error",
254+
});
255+
}
256+
},
257+
[pages],
258+
);
235259

236260
const handlePageInputChange = useCallback((value: string) => {
237261
setNewPageInput(value);
@@ -263,21 +287,26 @@ const LeftSidebarGlobalSectionsContent = ({
263287
border: "1px solid rgba(51, 51, 51, 0.2)",
264288
}}
265289
>
266-
<FlagPanel
290+
<GlobalFlagPanel
267291
title="Folded"
268292
description="If children are present, start with global section collapsed in left sidebar"
293+
settingKeys={["Left sidebar", "Settings", "Folded"]}
294+
initialValue={globalSection.settings?.folded?.value || false}
269295
order={0}
270296
uid={globalSection.settings?.folded?.uid || ""}
271297
parentUid={globalSection.settings?.uid || ""}
272298
disabled={!globalSection.children?.length}
299+
273300
/>
274-
<FlagPanel
301+
<GlobalFlagPanel
275302
title="Collapsable"
276303
description="Make global section collapsable"
304+
settingKeys={["Left sidebar", "Settings", "Collapsable"]}
305+
initialValue={globalSection.settings?.collapsable?.value || false}
277306
order={1}
278307
uid={globalSection.settings?.collapsable?.uid || ""}
279308
parentUid={globalSection.settings?.uid || ""}
280-
value={globalSection.settings?.collapsable?.value || false}
309+
281310
/>
282311
</div>
283312

0 commit comments

Comments
 (0)