11import { VSCodeButton , VSCodeCheckbox , VSCodeLink , VSCodeTextArea } from "@vscode/webview-ui-toolkit/react"
2- import { memo , useCallback , useEffect , useState } from "react"
3- import { validateApiConfiguration , validateModelId } from "../../utils/validate"
2+ import { memo , useEffect , useState } from "react"
3+ import { validateApiConfiguration , validateEmbeddingConfiguration , validateModelId } from "../../utils/validate"
44import { useExtensionState } from "../../context/ExtensionStateContext"
55import { vscode } from "../../utils/vscode"
66import ApiOptions from "./ApiOptions"
77import SettingsViewExtra from "./SettingsViewExtra"
88import EmbeddingOptions from "./EmbeddingOptions"
99import SettingsButton from "../common/SettingsButton"
10- import { useDebounce , useDeepCompareEffect } from "react-use"
1110import { CREATE_HAI_RULES_PROMPT , HAI_RULES_PATH } from "../../utils/constants"
1211import { TabButton } from "../mcp/McpView"
13- import { useEvent } from "react-use"
14- import { ExtensionMessage } from "../../../../src/shared/ExtensionMessage"
1512
1613const IS_DEV = true // FIXME: use flags when packaging
1714
@@ -65,21 +62,27 @@ const SettingsView = ({ onDone }: SettingsViewProps) => {
6562 }
6663 }
6764
68- useDebounce (
69- ( ) => {
70- vscode . postMessage ( { type : "customInstructions" , text : customInstructions || "" } )
71- } ,
72- 500 ,
73- [ customInstructions ] ,
74- )
65+ const handleSubmit = ( withoutDone : boolean = false ) => {
66+ const apiValidationResult = validateApiConfiguration ( apiConfiguration )
67+ const modelIdValidationResult = validateModelId ( apiConfiguration , openRouterModels )
7568
76- useEffect ( ( ) => {
77- vscode . postMessage ( { type : "telemetrySetting" , telemetrySetting } )
78- } , [ telemetrySetting ] )
69+ if ( ! apiValidationResult && ! modelIdValidationResult ) {
70+ vscode . postMessage ( { type : "apiConfiguration" , apiConfiguration } )
71+ vscode . postMessage ( { type : "buildContextOptions" , buildContextOptions : buildContextOptions } )
72+ vscode . postMessage ( { type : "embeddingConfiguration" , embeddingConfiguration } )
73+ }
7974
80- useEffect ( ( ) => {
81- vscode . postMessage ( { type : "updateSettings" , planActSeparateModelsSetting } )
82- } , [ planActSeparateModelsSetting ] )
75+ vscode . postMessage ( {
76+ type : "updateSettings" ,
77+ planActSeparateModelsSetting,
78+ customInstructionsSetting : customInstructions ,
79+ telemetrySetting,
80+ } )
81+
82+ if ( ! withoutDone ) {
83+ onDone ( )
84+ }
85+ }
8386
8487 useEffect ( ( ) => {
8588 if ( pendingTabChange ) {
@@ -92,15 +95,12 @@ const SettingsView = ({ onDone }: SettingsViewProps) => {
9295 }
9396 } , [ pendingTabChange ] )
9497
95- useDeepCompareEffect ( ( ) => {
96- vscode . postMessage ( { type : "buildContextOptions" , buildContextOptions : buildContextOptions } )
97- } , [ buildContextOptions ] )
98-
9998 const handleTabChange = ( tab : "plan" | "act" ) => {
10099 if ( tab === chatSettings . mode ) {
101100 return
102101 }
103102 setPendingTabChange ( tab )
103+ handleSubmit ( true )
104104 }
105105
106106 return (
@@ -125,6 +125,7 @@ const SettingsView = ({ onDone }: SettingsViewProps) => {
125125 paddingRight : 17 ,
126126 } } >
127127 < h3 style = { { color : "var(--vscode-foreground)" , margin : 0 } } > Settings</ h3 >
128+ < VSCodeButton onClick = { ( ) => handleSubmit ( false ) } > Done</ VSCodeButton >
128129 </ div >
129130 < div
130131 style = { {
0 commit comments