Skip to content

Commit 16b87c3

Browse files
committed
show alert to reload the graph when left sidebar is enabled
1 parent aaf9dee commit 16b87c3

File tree

1 file changed

+53
-8
lines changed

1 file changed

+53
-8
lines changed

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

Lines changed: 53 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,28 @@
1-
import React, { useMemo } from "react";
1+
import React, { useMemo, useState } from "react";
22
import TextPanel from "roamjs-components/components/ConfigPanels/TextPanel";
33
import FlagPanel from "roamjs-components/components/ConfigPanels/FlagPanel";
44
import { getFormattedConfigTree } from "~/utils/discourseConfigRef";
55
import refreshConfigTree from "~/utils/refreshConfigTree";
66
import { DEFAULT_CANVAS_PAGE_FORMAT } from "~/index";
7+
import { Alert, Checkbox, Intent } from "@blueprintjs/core";
8+
import Description from "roamjs-components/components/Description";
9+
import createBlock from "roamjs-components/writes/createBlock";
10+
import deleteBlock from "roamjs-components/writes/deleteBlock";
711

812
const DiscourseGraphHome = () => {
913
const settings = useMemo(() => {
1014
refreshConfigTree();
1115
return getFormattedConfigTree();
1216
}, []);
1317

18+
const [leftSidebarEnabled, setLeftSidebarEnabled] = useState(
19+
settings.leftSidebarEnabled.value || false,
20+
);
21+
const [leftSidebarUid, setLeftSidebarUid] = useState(
22+
settings.leftSidebarEnabled.uid,
23+
);
24+
const [isAlertOpen, setIsAlertOpen] = useState(false);
25+
1426
return (
1527
<div className="flex flex-col gap-4 p-1">
1628
<TextPanel
@@ -30,14 +42,47 @@ const DiscourseGraphHome = () => {
3042
value={settings.canvasPageFormat.value}
3143
defaultValue={DEFAULT_CANVAS_PAGE_FORMAT}
3244
/>
33-
<FlagPanel
34-
title="(BETA) Left Sidebar"
35-
description="Whether or not to enable the left sidebar."
36-
order={2}
37-
uid={settings.leftSidebarEnabled.uid}
38-
parentUid={settings.settingsUid}
39-
value={settings.leftSidebarEnabled.value || false}
45+
<Checkbox
46+
checked={leftSidebarEnabled}
47+
onChange={(e) => {
48+
const checked = (e.target as HTMLInputElement).checked;
49+
if (checked) {
50+
void createBlock({
51+
parentUid: settings.settingsUid,
52+
node: { text: "(BETA) Left Sidebar" },
53+
}).then((uid) => {
54+
setLeftSidebarUid(uid);
55+
setLeftSidebarEnabled(true);
56+
setIsAlertOpen(true);
57+
});
58+
} else {
59+
if (leftSidebarUid) {
60+
void deleteBlock(leftSidebarUid);
61+
setLeftSidebarUid(undefined);
62+
}
63+
setLeftSidebarEnabled(false);
64+
}
65+
}}
66+
labelElement={
67+
<>
68+
(BETA) Left Sidebar
69+
<Description
70+
description={"Whether or not to enable the left sidebar."}
71+
/>
72+
</>
73+
}
4074
/>
75+
<Alert
76+
isOpen={isAlertOpen}
77+
onConfirm={() => window.location.reload()}
78+
onCancel={() => setIsAlertOpen(false)}
79+
confirmButtonText="Reload Graph"
80+
cancelButtonText="Later"
81+
intent={Intent.PRIMARY}
82+
>
83+
<p>Enabling the Left Sidebar requires a graph reload to take effect.</p>
84+
<p>Would you like to reload now?</p>
85+
</Alert>
4186
<FlagPanel
4287
title="(BETA) Suggestive Mode Enabled"
4388
description="Whether or not to enable the suggestive mode, if this is first time enabling it, you will need to generate and upload all node embeddings to supabase. Go to Suggestive Mode -> Sync Config -> Click on 'Generate & Upload All Node Embeddings'"

0 commit comments

Comments
 (0)