From 7646a2e33d19ac033ea279423075260bbc3f6472 Mon Sep 17 00:00:00 2001 From: sam hoang Date: Mon, 20 Jan 2025 15:59:46 +0700 Subject: [PATCH] fix: config-manager --- webview-ui/src/components/settings/ApiOptions.tsx | 2 +- webview-ui/src/context/ExtensionStateContext.tsx | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/webview-ui/src/components/settings/ApiOptions.tsx b/webview-ui/src/components/settings/ApiOptions.tsx index 8e6fe42..cad94a8 100644 --- a/webview-ui/src/components/settings/ApiOptions.tsx +++ b/webview-ui/src/components/settings/ApiOptions.tsx @@ -56,7 +56,7 @@ const ApiOptions = ({ apiErrorMessage, modelIdErrorMessage }: ApiOptionsProps) = const handleInputChange = (field: keyof ApiConfiguration) => (event: any) => { const apiConfig = { ...apiConfiguration, [field]: event.target.value } onUpdateApiConfig(apiConfig) - setApiConfiguration(apiConfig) + // setApiConfiguration(apiConfig) } const { selectedProvider, selectedModelId, selectedModelInfo } = useMemo(() => { diff --git a/webview-ui/src/context/ExtensionStateContext.tsx b/webview-ui/src/context/ExtensionStateContext.tsx index f98abc4..868bc97 100644 --- a/webview-ui/src/context/ExtensionStateContext.tsx +++ b/webview-ui/src/context/ExtensionStateContext.tsx @@ -112,19 +112,19 @@ export const ExtensionStateContextProvider: React.FC<{ children: React.ReactNode const setListApiConfigMeta = useCallback( (value: ApiConfigMeta[]) => setState((prevState) => ({ ...prevState, listApiConfigMeta: value })), - [setState], + [], ) - const onUpdateApiConfig = useCallback( - (apiConfig: ApiConfiguration) => { + const onUpdateApiConfig = useCallback((apiConfig: ApiConfiguration) => { + setState((currentState) => { vscode.postMessage({ type: "upsertApiConfiguration", - text: state.currentApiConfigName, + text: currentState.currentApiConfigName, // Access latest state apiConfiguration: apiConfig, }) - }, - [state], - ) + return currentState // No state update needed + }) + }, []) const handleMessage = useCallback( (event: MessageEvent) => {