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,96 @@ 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- }
75+
11376 />
11477 ) }
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- }
78+ < PersonalFlagPanel
79+ title = "Text Selection Popup"
80+ description = "Whether or not to show the Discourse Node Menu when selecting text."
81+ settingKeys = { [ "Text Selection Popup" ] }
82+ defaultValue = { true }
13383 />
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- }
84+ < PersonalFlagPanel
85+ title = "Disable Sidebar Open"
86+ description = "Disable opening new nodes in the sidebar when created"
87+ settingKeys = { [ "Disable Sidebar Open" ] }
15288 />
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 ) ;
89+ < PersonalFlagPanel
90+ title = "Preview"
91+ description = "Whether or not to display page previews when hovering over page refs"
92+ settingKeys = { [ "Page Preview" ] }
93+ onChange = { ( checked ) => {
94+ onPageRefObserverChange ( previewPageRefHandler ) ( checked ) ;
15995 } }
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- }
17096 />
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 ) {
97+ < PersonalFlagPanel
98+ title = "Hide Feedback Button"
99+ description = "Hide the 'Send feedback' button at the bottom right of the screen."
100+ settingKeys = { [ "Hide Feedback Button" ] }
101+ onChange = { ( checked ) => {
102+ if ( checked ) {
180103 hideDiscourseFloatingMenu ( ) ;
181104 } else {
182105 showDiscourseFloatingMenu ( ) ;
183106 }
184107 } }
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- }
195- />
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- }
217108 />
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- }
109+ < PersonalFlagPanel
110+ title = "Auto Canvas Relations"
111+ description = "Automatically add discourse relations to canvas when a node is added"
112+ settingKeys = { [ "Auto Canvas Relations" ] }
240113 />
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- ) ;
248114
249- // Load or unload the streamline styling
115+ < PersonalFlagPanel
116+ title = "(BETA) Overlay in Canvas"
117+ description = "Whether or not to overlay Discourse Context information over Canvas Nodes."
118+ settingKeys = { [ "Overlay in Canvas" ] }
119+ />
120+ < PersonalFlagPanel
121+ title = "Streamline Styling"
122+ description = "Apply streamlined styling to your personal graph for a cleaner appearance."
123+ settingKeys = { [ "Streamline Styling" ] }
124+ onChange = { ( checked ) => {
250125 const existingStyleElement =
251126 document . getElementById ( "streamline-styling" ) ;
252127
253- if ( target . checked && ! existingStyleElement ) {
254- // Load the styles
128+ if ( checked && ! existingStyleElement ) {
255129 const styleElement = addStyle ( streamlineStyling ) ;
256130 styleElement . id = "streamline-styling" ;
257- } else if ( ! target . checked && existingStyleElement ) {
258- // Unload the styles
131+ } else if ( ! checked && existingStyleElement ) {
259132 existingStyleElement . remove ( ) ;
260133 }
261134 } }
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- }
272135 />
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- } ) ;
136+ < PersonalFlagPanel
137+ title = "Disable Product Diagnostics"
138+ description = "Disable sending usage signals and error reports that help us improve the product."
139+ settingKeys = { [ "Disable Product Diagnostics" ] }
140+ onChange = { ( checked ) => {
141+ if ( checked ) {
142+ disablePostHog ( ) ;
143+ } else {
144+ enablePostHog ( ) ;
145+ }
293146 } }
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- }
304147 />
305148 </ div >
306149 ) ;
0 commit comments