Skip to content

Commit 308621a

Browse files
committed
ENG-1217: Port section component in left sidebar
1 parent 1662562 commit 308621a

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";
@@ -18,6 +19,9 @@ import { refreshAndNotify } from "~/components/LeftSidebarView";
1819
import getPageTitleByPageUid from "roamjs-components/queries/getPageTitleByPageUid";
1920
import getTextByBlockUid from "roamjs-components/queries/getTextByBlockUid";
2021

22+
const pagesToUids = (pages: RoamBasicNode[]) => pages.map((p) => p.text);
23+
24+
2125
const PageItem = memo(
2226
({
2327
page,
@@ -159,6 +163,11 @@ const LeftSidebarGlobalSectionsContent = ({
159163
newPages.splice(newIndex, 0, removed);
160164

161165
setPages(newPages);
166+
setGlobalSetting(
167+
["Left sidebar", "Children"],
168+
pagesToUids(newPages),
169+
);
170+
162171

163172
if (childrenUid) {
164173
const order = direction === "down" ? newIndex + 1 : newIndex;
@@ -200,7 +209,13 @@ const LeftSidebarGlobalSectionsContent = ({
200209
children: [],
201210
};
202211

203-
setPages((prev) => [...prev, newPage]);
212+
const updatedPages = [...pages, newPage];
213+
setPages(updatedPages);
214+
setGlobalSetting(
215+
["Left sidebar", "Children"],
216+
pagesToUids(updatedPages),
217+
);
218+
204219
setNewPageInput("");
205220
setAutocompleteKey((prev) => prev + 1);
206221
refreshAndNotify();
@@ -215,19 +230,28 @@ const LeftSidebarGlobalSectionsContent = ({
215230
[childrenUid, pages],
216231
);
217232

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

232256
const handlePageInputChange = useCallback((value: string) => {
233257
setNewPageInput(value);
@@ -259,21 +283,26 @@ const LeftSidebarGlobalSectionsContent = ({
259283
border: "1px solid rgba(51, 51, 51, 0.2)",
260284
}}
261285
>
262-
<FlagPanel
286+
<GlobalFlagPanel
263287
title="Folded"
264288
description="If children are present, start with global section collapsed in left sidebar"
289+
settingKeys={["Left sidebar", "Settings", "Folded"]}
290+
initialValue={globalSection.settings?.folded?.value || false}
265291
order={0}
266292
uid={globalSection.settings?.folded?.uid || ""}
267293
parentUid={globalSection.settings?.uid || ""}
268294
disabled={!globalSection.children?.length}
295+
269296
/>
270-
<FlagPanel
297+
<GlobalFlagPanel
271298
title="Collapsable"
272299
description="Make global section collapsable"
300+
settingKeys={["Left sidebar", "Settings", "Collapsable"]}
301+
initialValue={globalSection.settings?.collapsable?.value || false}
273302
order={1}
274303
uid={globalSection.settings?.collapsable?.uid || ""}
275304
parentUid={globalSection.settings?.uid || ""}
276-
value={globalSection.settings?.collapsable?.value || false}
305+
277306
/>
278307
</div>
279308

0 commit comments

Comments
 (0)