Browse Source

fix: sync model picker search terms with selected models

Added useEffect hooks to GlamaModelPicker, OpenAiModelPicker, and OpenRouterModelPicker components to ensure the search term stays synchronized with the selected model ID from apiConfiguration. This prevents the search term from getting out of sync when the model is changed.
sam hoang 1 year ago
parent
commit
f39eaa14ff

+ 9 - 0
webview-ui/src/components/settings/GlamaModelPicker.tsx

@@ -37,6 +37,15 @@ const GlamaModelPicker: React.FC = () => {
 		return normalizeApiConfiguration(apiConfiguration)
 		return normalizeApiConfiguration(apiConfiguration)
 	}, [apiConfiguration])
 	}, [apiConfiguration])
 
 
+
+	useEffect(() => {
+		if (apiConfiguration?.glamaModelId) {
+			if (apiConfiguration?.glamaModelId !== searchTerm) {
+				setSearchTerm(apiConfiguration?.glamaModelId)
+			}
+		}
+	}, [apiConfiguration, searchTerm])
+
 	useMount(() => {
 	useMount(() => {
 		vscode.postMessage({ type: "refreshGlamaModels" })
 		vscode.postMessage({ type: "refreshGlamaModels" })
 	})
 	})

+ 8 - 0
webview-ui/src/components/settings/OpenAiModelPicker.tsx

@@ -28,6 +28,14 @@ const OpenAiModelPicker: React.FC = () => {
 		setSearchTerm(newModelId)
 		setSearchTerm(newModelId)
 	}
 	}
 
 
+	useEffect(() => {
+		if (apiConfiguration?.openAiModelId) {
+			if (apiConfiguration?.openAiModelId !== searchTerm) {
+				setSearchTerm(apiConfiguration?.openAiModelId)
+			}
+		}
+	}, [apiConfiguration, searchTerm])
+
 	useEffect(() => {
 	useEffect(() => {
 		if (!apiConfiguration?.openAiBaseUrl || !apiConfiguration?.openAiApiKey) {
 		if (!apiConfiguration?.openAiBaseUrl || !apiConfiguration?.openAiApiKey) {
 			return
 			return

+ 8 - 0
webview-ui/src/components/settings/OpenRouterModelPicker.tsx

@@ -37,6 +37,14 @@ const OpenRouterModelPicker: React.FC = () => {
 		return normalizeApiConfiguration(apiConfiguration)
 		return normalizeApiConfiguration(apiConfiguration)
 	}, [apiConfiguration])
 	}, [apiConfiguration])
 
 
+	useEffect(() => {
+		if (apiConfiguration?.openRouterModelId) {
+			if (apiConfiguration?.openRouterModelId !== searchTerm) {
+				setSearchTerm(apiConfiguration?.openRouterModelId)
+			}
+		}
+	}, [apiConfiguration, searchTerm])
+
 	useMount(() => {
 	useMount(() => {
 		vscode.postMessage({ type: "refreshOpenRouterModels" })
 		vscode.postMessage({ type: "refreshOpenRouterModels" })
 	})
 	})