Skip to content

Commit cdab9aa

Browse files
committed
refactor(SettingsView, ExtensionStateContext): streamline state updates for diff settings
1 parent 0406afa commit cdab9aa

File tree

2 files changed

+9
-30
lines changed

2 files changed

+9
-30
lines changed

webview-ui/src/components/settings/SettingsView.tsx

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,6 @@ const SettingsView = forwardRef<SettingsViewRef, SettingsViewProps>(({ onDone, t
137137
browserToolEnabled,
138138
browserViewportSize,
139139
enableCheckpoints,
140-
diffViewAutoFocus,
141-
autoCloseRooTabs,
142-
autoCloseAllRooTabs,
143-
diffEnabled,
144140
experiments,
145141
fuzzyMatchThreshold,
146142
maxOpenTabsContext,
@@ -215,25 +211,8 @@ const SettingsView = forwardRef<SettingsViewRef, SettingsViewProps>(({ onDone, t
215211
return prevState
216212
}
217213

218-
const newState: ExtensionStateContextType = {
219-
...prevState,
220-
apiConfiguration: { ...prevState.apiConfiguration, [field]: value },
221-
}
222-
// Update the field in root state for sync
223-
if (field === "diffEnabled") {
224-
newState.diffEnabled = value as boolean // type is boolean
225-
} else if (field === "diffViewAutoFocus") {
226-
newState.diffViewAutoFocus = value as boolean // type is boolean
227-
} else if (field === "autoCloseRooTabs") {
228-
newState.autoCloseRooTabs = value as boolean // type is boolean
229-
} else if (field === "autoCloseAllRooTabs") {
230-
newState.autoCloseAllRooTabs = value as boolean // type is boolean
231-
} else if (field === "fuzzyMatchThreshold") {
232-
newState.fuzzyMatchThreshold = value as number // type is number
233-
}
234-
235214
setChangeDetected(true)
236-
return newState
215+
return { ...prevState, apiConfiguration: { ...prevState.apiConfiguration, [field]: value } }
237216
})
238217
},
239218
[],
@@ -285,10 +264,10 @@ const SettingsView = forwardRef<SettingsViewRef, SettingsViewProps>(({ onDone, t
285264
vscode.postMessage({ type: "ttsEnabled", bool: ttsEnabled })
286265
vscode.postMessage({ type: "ttsSpeed", value: ttsSpeed })
287266
vscode.postMessage({ type: "soundVolume", value: soundVolume })
288-
vscode.postMessage({ type: "diffEnabled", bool: diffEnabled })
289-
vscode.postMessage({ type: "diffViewAutoFocus", bool: diffViewAutoFocus })
290-
vscode.postMessage({ type: "autoCloseRooTabs", bool: autoCloseRooTabs })
291-
vscode.postMessage({ type: "autoCloseAllRooTabs", bool: autoCloseAllRooTabs })
267+
vscode.postMessage({ type: "diffEnabled", bool: apiConfiguration.diffEnabled })
268+
vscode.postMessage({ type: "diffViewAutoFocus", bool: apiConfiguration.diffViewAutoFocus })
269+
vscode.postMessage({ type: "autoCloseRooTabs", bool: apiConfiguration.autoCloseRooTabs })
270+
vscode.postMessage({ type: "autoCloseAllRooTabs", bool: apiConfiguration.autoCloseAllRooTabs })
292271
vscode.postMessage({ type: "enableCheckpoints", bool: enableCheckpoints })
293272
vscode.postMessage({ type: "browserViewportSize", text: browserViewportSize })
294273
vscode.postMessage({ type: "remoteBrowserHost", text: remoteBrowserHost })

webview-ui/src/context/ExtensionStateContext.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -345,10 +345,10 @@ export const ExtensionStateContextProvider: React.FC<{ children: React.ReactNode
345345
setSoundVolume: (value) => setState((prevState) => ({ ...prevState, soundVolume: value })),
346346
setTtsEnabled: (value) => setState((prevState) => ({ ...prevState, ttsEnabled: value })),
347347
setTtsSpeed: (value) => setState((prevState) => ({ ...prevState, ttsSpeed: value })),
348-
setDiffEnabled: (value) => setState((prevState) => ({ ...prevState, diffEnabled: value })),
349-
setDiffViewAutoFocus: (value) => setState((prevState) => ({ ...prevState, diffViewAutoFocus: value })),
350-
setAutoCloseRooTabs: (value) => setState((prevState) => ({ ...prevState, autoCloseRooTabs: value })),
351-
setAutoCloseAllRooTabs: (value) => setState((prevState) => ({ ...prevState, autoCloseAllRooTabs: value })), // Added new setter
348+
setDiffEnabled: (value) => setApiConfiguration({ diffEnabled: value }),
349+
setDiffViewAutoFocus: (value) => setApiConfiguration({ diffViewAutoFocus: value }),
350+
setAutoCloseRooTabs: (value) => setApiConfiguration({ autoCloseRooTabs: value }),
351+
setAutoCloseAllRooTabs: (value) => setApiConfiguration({ autoCloseAllRooTabs: value }),
352352
setEnableCheckpoints: (value) => setState((prevState) => ({ ...prevState, enableCheckpoints: value })),
353353
setBrowserViewportSize: (value: string) =>
354354
setState((prevState) => ({ ...prevState, browserViewportSize: value })),

0 commit comments

Comments
 (0)