fix: config-manager

This commit is contained in:
sam hoang
2025-01-20 23:07:40 +07:00
parent 2ba64d68f2
commit eff72eea3f
5 changed files with 71 additions and 32 deletions

View File

@@ -65,6 +65,7 @@ export interface ExtensionStateContextType extends ExtensionState {
setExperimentalDiffStrategy: (value: boolean) => void
autoApprovalEnabled?: boolean
setAutoApprovalEnabled: (value: boolean) => void
handleInputChange: (field: keyof ApiConfiguration) => (event: any) => void
}
export const ExtensionStateContext = createContext<ExtensionStateContextType | undefined>(undefined)
@@ -117,15 +118,33 @@ export const ExtensionStateContextProvider: React.FC<{ children: React.ReactNode
const onUpdateApiConfig = useCallback((apiConfig: ApiConfiguration) => {
setState((currentState) => {
console.log("onUpdateApiConfig", currentState, apiConfig)
vscode.postMessage({
type: "upsertApiConfiguration",
text: currentState.currentApiConfigName, // Access latest state
text: currentState.currentApiConfigName,
apiConfiguration: apiConfig,
})
return currentState // No state update needed
})
}, [])
const handleInputChange = useCallback(
(field: keyof ApiConfiguration) => (event: any) => {
setState((currentState) => {
console.log("handleInputChange", currentState, event)
vscode.postMessage({
type: "upsertApiConfiguration",
text: currentState.currentApiConfigName,
apiConfiguration: { ...currentState.apiConfiguration, [field]: event.target.value },
})
return currentState // No state update needed
})
},
[],
)
const handleMessage = useCallback(
(event: MessageEvent) => {
const message: ExtensionMessage = event.data
@@ -258,6 +277,7 @@ export const ExtensionStateContextProvider: React.FC<{ children: React.ReactNode
setExperimentalDiffStrategy: (value) =>
setState((prevState) => ({ ...prevState, experimentalDiffStrategy: value })),
setAutoApprovalEnabled: (value) => setState((prevState) => ({ ...prevState, autoApprovalEnabled: value })),
handleInputChange,
}
return <ExtensionStateContext.Provider value={contextValue}>{children}</ExtensionStateContext.Provider>