11import React from "react" ;
22import { OnloadArgs } from "roamjs-components/types" ;
3- import { Label , Checkbox } from "@blueprintjs/core" ;
3+ import { Label } from "@blueprintjs/core" ;
44import Description from "roamjs-components/components/Description" ;
55import { addStyle } from "roamjs-components/dom" ;
66import { NodeMenuTriggerComponent } from "~/components/DiscourseNodeMenu" ;
@@ -15,19 +15,12 @@ import {
1515 hideDiscourseFloatingMenu ,
1616} from "~/components/DiscourseFloatingMenu" ;
1717import { NodeSearchMenuTriggerSetting } from "../DiscourseNodeSearchMenu" ;
18- import {
19- AUTO_CANVAS_RELATIONS_KEY ,
20- DISCOURSE_CONTEXT_OVERLAY_IN_CANVAS_KEY ,
21- DISCOURSE_TOOL_SHORTCUT_KEY ,
22- STREAMLINE_STYLING_KEY ,
23- DISALLOW_DIAGNOSTICS ,
24- } from "~/data/userSettings" ;
18+ import { DISCOURSE_TOOL_SHORTCUT_KEY } from "~/data/userSettings" ;
2519import { enablePostHog , disablePostHog } from "~/utils/posthog" ;
26- import internalError from "~/utils/internalError" ;
2720import KeyboardShortcutInput from "./KeyboardShortcutInput" ;
28- import { getSetting , setSetting } from "~/utils/extensionSettings" ;
2921import streamlineStyling from "~/styles/streamlineStyling" ;
3022import { useFeatureFlag } from "./utils/hooks" ;
23+ import { PersonalFlagPanel } from "./components/BlockPropSettingPanels" ;
3124
3225const HomePersonalSettings = ( { onloadArgs } : { onloadArgs : OnloadArgs } ) => {
3326 const extensionAPI = onloadArgs . extensionAPI ;
@@ -61,246 +54,94 @@ const HomePersonalSettings = ({ onloadArgs }: { onloadArgs: OnloadArgs }) => {
6154 description = "Set a single key to activate the Discourse Tool in tldraw. Only single keys (no modifiers) are supported. Leave empty for no shortcut."
6255 placeholder = "Click to set single key"
6356 />
64- < Checkbox
65- defaultChecked = {
66- extensionAPI . settings . get ( "discourse-context-overlay" ) as boolean
67- }
68- onChange = { ( e ) => {
69- const target = e . target as HTMLInputElement ;
70- extensionAPI . settings . set (
71- "discourse-context-overlay" ,
72- target . checked ,
73- ) ;
74-
75- onPageRefObserverChange ( overlayHandler ) ( target . checked ) ;
57+ < PersonalFlagPanel
58+ title = "Overlay"
59+ description = "Whether or not to overlay Discourse Context information over Discourse Node references."
60+ settingKeys = { [ "Discourse Context Overlay" ] }
61+ onChange = { ( checked ) => {
62+ onPageRefObserverChange ( overlayHandler ) ( checked ) ;
7663 } }
77- labelElement = {
78- < >
79- Overlay
80- < Description
81- description = {
82- "Whether or not to overlay Discourse Context information over Discourse Node references."
83- }
84- />
85- </ >
86- }
8764 />
8865 { suggestiveModeEnabled && (
89- < Checkbox
90- defaultChecked = {
91- extensionAPI . settings . get ( "suggestive-mode-overlay" ) as boolean
92- }
93- onChange = { ( e ) => {
94- const target = e . target as HTMLInputElement ;
95- void extensionAPI . settings . set (
96- "suggestive-mode-overlay" ,
97- target . checked ,
98- ) ;
66+ < PersonalFlagPanel
67+ title = "Suggestive Mode Overlay"
68+ description = "Whether or not to overlay Suggestive Mode button over Discourse Node references."
69+ settingKeys = { [ "Suggestive Mode Overlay" ] }
70+ onChange = { ( checked ) => {
9971 onPageRefObserverChange ( getSuggestiveOverlayHandler ( onloadArgs ) ) (
100- target . checked ,
72+ checked ,
10173 ) ;
10274 } }
103- labelElement = {
104- < >
105- Suggestive Mode Overlay
106- < Description
107- description = {
108- "Whether or not to overlay Suggestive Mode button over Discourse Node references."
109- }
110- />
111- </ >
112- }
11375 />
11476 ) }
115- < Checkbox
116- defaultChecked = {
117- extensionAPI . settings . get ( "text-selection-popup" ) !== false
118- }
119- onChange = { ( e ) => {
120- const target = e . target as HTMLInputElement ;
121- extensionAPI . settings . set ( "text-selection-popup" , target . checked ) ;
122- } }
123- labelElement = {
124- < >
125- Text Selection Popup
126- < Description
127- description = {
128- "Whether or not to show the Discourse Node Menu when selecting text."
129- }
130- />
131- </ >
132- }
77+ < PersonalFlagPanel
78+ title = "Text Selection Popup"
79+ description = "Whether or not to show the Discourse Node Menu when selecting text."
80+ settingKeys = { [ "Text Selection Popup" ] }
81+ defaultValue = { true }
13382 />
134- < Checkbox
135- defaultChecked = {
136- extensionAPI . settings . get ( "disable-sidebar-open" ) as boolean
137- }
138- onChange = { ( e ) => {
139- const target = e . target as HTMLInputElement ;
140- extensionAPI . settings . set ( "disable-sidebar-open" , target . checked ) ;
141- } }
142- labelElement = {
143- < >
144- Disable Sidebar Open
145- < Description
146- description = {
147- "Disable opening new nodes in the sidebar when created"
148- }
149- />
150- </ >
151- }
83+ < PersonalFlagPanel
84+ title = "Disable Sidebar Open"
85+ description = "Disable opening new nodes in the sidebar when created"
86+ settingKeys = { [ "Disable Sidebar Open" ] }
15287 />
153- < Checkbox
154- defaultChecked = { extensionAPI . settings . get ( "page-preview" ) as boolean }
155- onChange = { ( e ) => {
156- const target = e . target as HTMLInputElement ;
157- extensionAPI . settings . set ( "page-preview" , target . checked ) ;
158- onPageRefObserverChange ( previewPageRefHandler ) ( target . checked ) ;
88+ < PersonalFlagPanel
89+ title = "Preview"
90+ description = "Whether or not to display page previews when hovering over page refs"
91+ settingKeys = { [ "Page Preview" ] }
92+ onChange = { ( checked ) => {
93+ onPageRefObserverChange ( previewPageRefHandler ) ( checked ) ;
15994 } }
160- labelElement = {
161- < >
162- Preview
163- < Description
164- description = {
165- "Whether or not to display page previews when hovering over page refs"
166- }
167- />
168- </ >
169- }
17095 />
171- < Checkbox
172- defaultChecked = {
173- extensionAPI . settings . get ( "hide-feedback-button" ) as boolean
174- }
175- onChange = { ( e ) => {
176- const target = e . target as HTMLInputElement ;
177- extensionAPI . settings . set ( "hide-feedback-button" , target . checked ) ;
178-
179- if ( target . checked ) {
96+ < PersonalFlagPanel
97+ title = "Hide Feedback Button"
98+ description = "Hide the 'Send feedback' button at the bottom right of the screen."
99+ settingKeys = { [ "Hide Feedback Button" ] }
100+ onChange = { ( checked ) => {
101+ if ( checked ) {
180102 hideDiscourseFloatingMenu ( ) ;
181103 } else {
182104 showDiscourseFloatingMenu ( ) ;
183105 }
184106 } }
185- labelElement = {
186- < >
187- Hide Feedback Button
188- < Description
189- description = {
190- "Hide the 'Send feedback' button at the bottom right of the screen."
191- }
192- />
193- </ >
194- }
195107 />
196- < Checkbox
197- defaultChecked = {
198- extensionAPI . settings . get ( AUTO_CANVAS_RELATIONS_KEY ) === true
199- }
200- onChange = { ( e ) => {
201- const target = e . target as HTMLInputElement ;
202- void extensionAPI . settings . set (
203- AUTO_CANVAS_RELATIONS_KEY ,
204- target . checked ,
205- ) ;
206- } }
207- labelElement = {
208- < >
209- Auto Canvas Relations
210- < Description
211- description = {
212- "Automatically add discourse relations to canvas when a node is added"
213- }
214- />
215- </ >
216- }
108+ < PersonalFlagPanel
109+ title = "Auto Canvas Relations"
110+ description = "Automatically add discourse relations to canvas when a node is added"
111+ settingKeys = { [ "Auto Canvas Relations" ] }
217112 />
218- < Checkbox
219- defaultChecked = { getSetting (
220- DISCOURSE_CONTEXT_OVERLAY_IN_CANVAS_KEY ,
221- false ,
222- ) }
223- onChange = { ( e ) => {
224- const target = e . target as HTMLInputElement ;
225- void setSetting (
226- DISCOURSE_CONTEXT_OVERLAY_IN_CANVAS_KEY ,
227- target . checked ,
228- ) . catch ( ( ) => undefined ) ;
229- } }
230- labelElement = {
231- < >
232- (BETA) Overlay in Canvas
233- < Description
234- description = {
235- "Whether or not to overlay Discourse Context information over Canvas Nodes."
236- }
237- />
238- </ >
239- }
113+ < PersonalFlagPanel
114+ title = "(BETA) Overlay in Canvas"
115+ description = "Whether or not to overlay Discourse Context information over Canvas Nodes."
116+ settingKeys = { [ "Overlay in Canvas" ] }
240117 />
241- < Checkbox
242- defaultChecked = { getSetting ( STREAMLINE_STYLING_KEY , false ) }
243- onChange = { ( e ) => {
244- const target = e . target as HTMLInputElement ;
245- void setSetting ( STREAMLINE_STYLING_KEY , target . checked ) . catch (
246- ( ) => undefined ,
247- ) ;
248-
249- // Load or unload the streamline styling
118+ < PersonalFlagPanel
119+ title = "Streamline Styling"
120+ description = "Apply streamlined styling to your personal graph for a cleaner appearance."
121+ settingKeys = { [ "Streamline Styling" ] }
122+ onChange = { ( checked ) => {
250123 const existingStyleElement =
251124 document . getElementById ( "streamline-styling" ) ;
252125
253- if ( target . checked && ! existingStyleElement ) {
254- // Load the styles
126+ if ( checked && ! existingStyleElement ) {
255127 const styleElement = addStyle ( streamlineStyling ) ;
256128 styleElement . id = "streamline-styling" ;
257- } else if ( ! target . checked && existingStyleElement ) {
258- // Unload the styles
129+ } else if ( ! checked && existingStyleElement ) {
259130 existingStyleElement . remove ( ) ;
260131 }
261132 } }
262- labelElement = {
263- < >
264- Streamline Styling
265- < Description
266- description = {
267- "Apply streamlined styling to your personal graph for a cleaner appearance."
268- }
269- />
270- </ >
271- }
272133 />
273- < Checkbox
274- defaultChecked = { getSetting ( DISALLOW_DIAGNOSTICS , false ) }
275- onChange = { ( e ) => {
276- const target = e . target as HTMLInputElement ;
277- const disallow = target . checked ;
278- void setSetting ( DISALLOW_DIAGNOSTICS , disallow )
279- . then ( ( ) => {
280- if ( disallow ) {
281- disablePostHog ( ) ;
282- } else {
283- enablePostHog ( ) ;
284- }
285- } )
286- . catch ( ( error ) => {
287- target . checked = ! disallow ;
288- internalError ( {
289- error,
290- userMessage : "Could not change settings" ,
291- } ) ;
292- } ) ;
134+ < PersonalFlagPanel
135+ title = "Disable Product Diagnostics"
136+ description = "Disable sending usage signals and error reports that help us improve the product."
137+ settingKeys = { [ "Disable Product Diagnostics" ] }
138+ onChange = { ( checked ) => {
139+ if ( checked ) {
140+ disablePostHog ( ) ;
141+ } else {
142+ enablePostHog ( ) ;
143+ }
293144 } }
294- labelElement = {
295- < >
296- Disable Product Diagnostics
297- < Description
298- description = {
299- "Disable sending usage signals and error reports that help us improve the product."
300- }
301- />
302- </ >
303- }
304145 />
305146 </ div >
306147 ) ;
0 commit comments