Skip to content

Commit b64e6e1

Browse files
committed
use global settings for BETA left sidebar feature
1 parent a303fed commit b64e6e1

File tree

8 files changed

+40
-41
lines changed

8 files changed

+40
-41
lines changed

apps/roam/src/components/LeftSidebarView.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ const PersonalSectionItem = ({
175175

176176
return (
177177
<>
178-
<div className="sidebar-title-button flex w-full cursor-pointer items-center border-none bg-transparent pl-7 pr-2.5 font-semibold outline-none">
178+
<div className="sidebar-title-button flex w-full cursor-pointer items-center border-none bg-transparent pl-6 pr-2.5 font-semibold outline-none">
179179
<div className="flex w-full items-center justify-between">
180180
<div
181181
className="flex items-center"
@@ -235,7 +235,7 @@ const GlobalSection = ({ config }: { config: LeftSidebarConfig["global"] }) => {
235235
return (
236236
<>
237237
<div
238-
className="sidebar-title-button flex w-full items-center border-none bg-transparent py-1 pl-7 pr-2.5 font-semibold outline-none"
238+
className="sidebar-title-button flex w-full items-center border-none bg-transparent py-1 pl-6 pr-2.5 font-semibold outline-none"
239239
onClick={() => {
240240
if (!isCollapsable || !config.settings) return;
241241
toggleFoldedState({
@@ -352,7 +352,7 @@ const FavouritesPopover = ({ onloadArgs }: { onloadArgs: OnloadArgs }) => {
352352
<>
353353
<Divider className="mx-5" style={{ borderColor: "rgb(57, 75, 89)" }} />
354354
<div style={{ height: "8px" }}></div>
355-
<div className="flex w-full items-center justify-between pb-1 pl-7 pr-2.5 font-semibold">
355+
<div className="flex w-full items-center justify-between pb-1 pl-6 pr-2.5 font-semibold">
356356
<span className="flex items-baseline">
357357
<Icon icon="star" iconSize={14} />
358358
<div style={{ width: 8 }}></div>

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React, { useMemo } from "react";
22
import TextPanel from "roamjs-components/components/ConfigPanels/TextPanel";
3+
import FlagPanel from "roamjs-components/components/ConfigPanels/FlagPanel";
34
import { getFormattedConfigTree } from "~/utils/discourseConfigRef";
45
import refreshConfigTree from "~/utils/refreshConfigTree";
56
import { DEFAULT_CANVAS_PAGE_FORMAT } from "~/index";
@@ -29,6 +30,14 @@ const DiscourseGraphHome = () => {
2930
value={settings.canvasPageFormat.value}
3031
defaultValue={DEFAULT_CANVAS_PAGE_FORMAT}
3132
/>
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}
40+
/>
3241
</div>
3342
);
3443
};

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

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import {
1717
AUTO_CANVAS_RELATIONS_KEY,
1818
DISCOURSE_CONTEXT_OVERLAY_IN_CANVAS_KEY,
1919
DISCOURSE_TOOL_SHORTCUT_KEY,
20-
LEFT_SIDEBAR_ENABLED_KEY,
2120
} from "~/data/userSettings";
2221
import KeyboardShortcutInput from "./KeyboardShortcutInput";
2322
import { getSetting, setSetting } from "~/utils/extensionSettings";
@@ -200,21 +199,6 @@ const HomePersonalSettings = ({ onloadArgs }: { onloadArgs: OnloadArgs }) => {
200199
</>
201200
}
202201
/>
203-
<Checkbox
204-
defaultChecked={getSetting(LEFT_SIDEBAR_ENABLED_KEY, false)}
205-
onChange={(e) => {
206-
const target = e.target as HTMLInputElement;
207-
setSetting(LEFT_SIDEBAR_ENABLED_KEY, target.checked);
208-
}}
209-
labelElement={
210-
<>
211-
(BETA) Left Sidebar
212-
<Description
213-
description={"Whether or not to enable the left sidebar."}
214-
/>
215-
</>
216-
}
217-
/>
218202
</div>
219203
);
220204
};

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useCallback, useEffect, useMemo, useState } from "react";
1+
import React, { useCallback, useEffect, useMemo, useState, memo } from "react";
22
import { Button, Collapse } from "@blueprintjs/core";
33
import FlagPanel from "roamjs-components/components/ConfigPanels/FlagPanel";
44
import AutocompleteInput from "roamjs-components/components/AutocompleteInput";
@@ -15,7 +15,6 @@ import { LeftSidebarGlobalSectionConfig } from "~/utils/getLeftSidebarSettings";
1515
import { render as renderToast } from "roamjs-components/components/Toast";
1616
import refreshConfigTree from "~/utils/refreshConfigTree";
1717
import { refreshAndNotify } from "~/components/LeftSidebarView";
18-
import { memo } from "react";
1918

2019
const PageItem = memo(
2120
({

apps/roam/src/data/userSettings.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,3 @@ export const AUTO_CANVAS_RELATIONS_KEY = "auto-canvas-relations";
77
export const DISCOURSE_TOOL_SHORTCUT_KEY = "discourse-tool-shortcut";
88
export const DISCOURSE_CONTEXT_OVERLAY_IN_CANVAS_KEY =
99
"discourse-context-overlay-in-canvas";
10-
export const LEFT_SIDEBAR_ENABLED_KEY = "left-sidebar-enabled";

apps/roam/src/styles/styles.css

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,3 @@
141141
background-color: #10161a;
142142
color: #f5f8fa;
143143
}
144-
145-
.starred-pages-wrapper {
146-
padding: 0 !important;
147-
}

apps/roam/src/utils/discourseConfigRef.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import {
44
StringSetting,
55
ExportConfigWithUids,
66
getUidAndStringSetting,
7+
getUidAndBooleanSetting,
8+
BooleanSetting,
79
} from "./getExportSettings";
810
import { DISCOURSE_CONFIG_PAGE_TITLE } from "~/utils/renderNodeConfigPage";
911
import getPageUidByPageTitle from "roamjs-components/queries/getPageUidByPageTitle";
@@ -29,10 +31,9 @@ export const subscribe = (listener: () => void) => {
2931
};
3032

3133
export const notify = () => {
32-
listeners.forEach(listener => listener());
34+
listeners.forEach((listener) => listener());
3335
};
3436

35-
3637
type FormattedConfigTree = {
3738
settingsUid: string;
3839
grammarUid: string;
@@ -43,6 +44,7 @@ type FormattedConfigTree = {
4344
canvasPageFormat: StringSetting;
4445
suggestiveMode: SuggestiveModeConfigWithUids;
4546
leftSidebar: LeftSidebarConfig;
47+
leftSidebarEnabled: BooleanSetting;
4648
};
4749

4850
export const getFormattedConfigTree = (): FormattedConfigTree => {
@@ -71,6 +73,10 @@ export const getFormattedConfigTree = (): FormattedConfigTree => {
7173
}),
7274
suggestiveMode: getSuggestiveModeConfigAndUids(configTreeRef.tree),
7375
leftSidebar: getLeftSidebarSettings(configTreeRef.tree),
76+
leftSidebarEnabled: getUidAndBooleanSetting({
77+
tree: configTreeRef.tree,
78+
text: "(BETA) Left Sidebar",
79+
}),
7480
};
7581
};
7682
export default configTreeRef;

apps/roam/src/utils/initializeObserversAndListeners.ts

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ import { renderNodeTagPopupButton } from "./renderNodeTagPopup";
4747
import { formatHexColor } from "~/components/settings/DiscourseNodeCanvasSettings";
4848
import { getSetting } from "./extensionSettings";
4949
import { mountLeftSidebar } from "~/components/LeftSidebarView";
50-
import { LEFT_SIDEBAR_ENABLED_KEY } from "~/data/userSettings";
50+
import { getUidAndBooleanSetting } from "./getExportSettings";
5151

5252
const debounce = (fn: () => void, delay = 250) => {
5353
let timeout: number;
@@ -102,18 +102,6 @@ export const initObservers = async ({
102102
render: (b) => renderQueryBlock(b, onloadArgs),
103103
});
104104

105-
const leftSidebarObserver = createHTMLObserver({
106-
tag: "DIV",
107-
useBody: true,
108-
className: "starred-pages-wrapper",
109-
callback: (el) => {
110-
const isLeftSidebarEnabled = getSetting(LEFT_SIDEBAR_ENABLED_KEY, false);
111-
if (!isLeftSidebarEnabled) return;
112-
const container = el as HTMLDivElement;
113-
mountLeftSidebar(container, onloadArgs);
114-
},
115-
});
116-
117105
const nodeTagPopupButtonObserver = createHTMLObserver({
118106
className: "rm-page-ref--tag",
119107
tag: "SPAN",
@@ -204,6 +192,24 @@ export const initObservers = async ({
204192
) as IKeyCombo) || undefined;
205193
const personalTrigger = personalTriggerCombo?.key;
206194
const personalModifiers = getModifiersFromCombo(personalTriggerCombo);
195+
196+
const leftSidebarObserver = createHTMLObserver({
197+
tag: "DIV",
198+
useBody: true,
199+
className: "starred-pages-wrapper",
200+
callback: (el) => {
201+
const isLeftSidebarEnabled = getUidAndBooleanSetting({
202+
tree: configTree,
203+
text: "(BETA) Left Sidebar",
204+
}).value;
205+
const container = el as HTMLDivElement;
206+
if (isLeftSidebarEnabled) {
207+
container.style.padding = "0";
208+
mountLeftSidebar(container, onloadArgs);
209+
}
210+
},
211+
});
212+
207213
const handleNodeMenuRender = (target: HTMLElement, evt: KeyboardEvent) => {
208214
if (
209215
target.tagName === "TEXTAREA" &&

0 commit comments

Comments
 (0)