@@ -5,14 +5,12 @@ import getDiscourseNodes, {
55 excludeDefaultNodes ,
66} from "~/utils/getDiscourseNodes" ;
77import { setPersonalSetting } from "~/components/settings/utils/accessors" ;
8- import { getSetting , setSetting } from "~/utils/extensionSettings" ;
8+ import { PERSONAL_KEYS } from "~/components/settings/utils/settingKeys" ;
9+ import { setSetting } from "~/utils/extensionSettings" ;
910import { CANVAS_NODE_SHORTCUTS_KEY } from "~/data/userSettings" ;
10- import type { CanvasNodeShortcuts } from "./utils/zodSchema" ;
11-
12- const BLOCK_PROP_KEY = "Canvas node shortcuts" ;
11+ import type { CanvasNodeShortcuts , PersonalSettings } from "./utils/zodSchema" ;
1312
1413type ShortcutRowProps = {
15- nodeType : string ;
1614 nodeText : string ;
1715 defaultShortcut : string ;
1816 initialEnabled : boolean ;
@@ -22,30 +20,24 @@ type ShortcutRowProps = {
2220} ;
2321
2422const ShortcutRow = ( {
25- nodeType,
2623 nodeText,
2724 defaultShortcut,
2825 initialEnabled,
2926 initialValue,
3027 onEnabledChange,
3128 onValueChange,
3229} : ShortcutRowProps ) => {
33- const enabledKey = [ BLOCK_PROP_KEY , nodeType , "enabled" ] ;
34- const valueKey = [ BLOCK_PROP_KEY , nodeType , "value" ] ;
35-
3630 const [ enabled , setEnabled ] = useState ( initialEnabled ) ;
3731 const [ storedValue , setStoredValue ] = useState ( initialValue ) ;
3832
3933 const persistValue = ( value : string ) => {
4034 setStoredValue ( value ) ;
41- setPersonalSetting ( valueKey , value ) ;
4235 onValueChange ( value ) ;
4336 } ;
4437
4538 const handleEnabledChange = ( e : React . FormEvent < HTMLInputElement > ) => {
4639 const checked = e . currentTarget . checked ;
4740 setEnabled ( checked ) ;
48- setPersonalSetting ( enabledKey , checked ) ;
4941 if ( ! checked ) {
5042 persistValue ( "" ) ;
5143 }
@@ -89,10 +81,16 @@ const ShortcutRow = ({
8981 ) ;
9082} ;
9183
92- const CanvasShortcutSettings = ( ) => {
84+ type CanvasShortcutSettingsProps = {
85+ personalSettings : PersonalSettings ;
86+ } ;
87+
88+ const CanvasShortcutSettings = ( {
89+ personalSettings,
90+ } : CanvasShortcutSettingsProps ) => {
9391 const nodes = getDiscourseNodes ( ) . filter ( excludeDefaultNodes ) ;
94- const [ shortcuts , setShortcuts ] = useState < CanvasNodeShortcuts > ( ( ) =>
95- getSetting < CanvasNodeShortcuts > ( CANVAS_NODE_SHORTCUTS_KEY , { } ) ,
92+ const [ shortcuts , setShortcuts ] = useState < CanvasNodeShortcuts > (
93+ ( ) => personalSettings [ PERSONAL_KEYS . canvasNodeShortcuts ] ,
9694 ) ;
9795
9896 const updateShortcut = (
@@ -102,6 +100,7 @@ const CanvasShortcutSettings = () => {
102100 const current = shortcuts [ nodeType ] ?? { value : "" , enabled : false } ;
103101 const next = { ...shortcuts , [ nodeType ] : { ...current , ...update } } ;
104102 void setSetting ( CANVAS_NODE_SHORTCUTS_KEY , next ) ;
103+ setPersonalSetting ( [ PERSONAL_KEYS . canvasNodeShortcuts ] , next ) ;
105104 setShortcuts ( next ) ;
106105 } ;
107106
@@ -125,7 +124,6 @@ const CanvasShortcutSettings = () => {
125124 return (
126125 < ShortcutRow
127126 key = { node . type }
128- nodeType = { node . type }
129127 nodeText = { node . text }
130128 defaultShortcut = { node . shortcut }
131129 initialEnabled = { override ?. enabled ?? false }
0 commit comments