Skip to content

Commit 5c5f031

Browse files
fix: save button implementation in settings (#141)
1 parent f0c437a commit 5c5f031

File tree

4 files changed

+30
-36
lines changed

4 files changed

+30
-36
lines changed

.changeset/perfect-mugs-hope.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"hai-build-code-generator": patch
3+
---
4+
5+
Replace AutoSave with a 'Done' button in settings to explicitly save configuration changes, improving clarity and user control.

src/core/controller/index.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -881,9 +881,6 @@ export class Controller {
881881
case "validateLLMConfig":
882882
let isValid = false
883883
if (message.apiConfiguration) {
884-
// Save the LLM configuration in the state
885-
await updateApiConfiguration(this.context, message.apiConfiguration, this.workspaceId)
886-
887884
// If no validation error is encountered, validate the LLM configuration by sending a test message.
888885
if (!message.text) {
889886
try {
@@ -906,9 +903,6 @@ export class Controller {
906903
case "validateEmbeddingConfig":
907904
let isEmbeddingValid = false
908905
if (message.embeddingConfiguration) {
909-
// Save the Embedding configuration in the state
910-
await updateEmbeddingConfiguration(this.context, message.embeddingConfiguration, this.workspaceId)
911-
912906
// If no validation error is encountered, validate the Embedding configuration by sending a test message.
913907
if (!message.text) {
914908
try {

webview-ui/src/components/chat/ChatView.tsx

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ interface ChatViewProps {
3737
showAnnouncement: boolean
3838
hideAnnouncement: () => void
3939
showHistoryView: () => void
40-
onTaskSelect: (task: IHaiClineTask) => void
40+
onTaskSelect: (task: IHaiClineTask | null) => void
4141
selectedHaiTask: IHaiClineTask | null
4242
haiConfig: {
4343
[x: string]: any
@@ -809,13 +809,7 @@ const ChatView = ({
809809
)
810810

811811
const clearSelectedHaiTaskId = () => {
812-
onTaskSelect({
813-
acceptance: selectedHaiTask?.acceptance ?? "",
814-
context: selectedHaiTask?.context ?? "",
815-
id: "",
816-
list: selectedHaiTask?.list ?? "",
817-
status: selectedHaiTask?.status ?? "",
818-
})
812+
onTaskSelect(null)
819813
}
820814

821815
return (

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

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
import { 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"
44
import { useExtensionState } from "../../context/ExtensionStateContext"
55
import { vscode } from "../../utils/vscode"
66
import ApiOptions from "./ApiOptions"
77
import SettingsViewExtra from "./SettingsViewExtra"
88
import EmbeddingOptions from "./EmbeddingOptions"
99
import SettingsButton from "../common/SettingsButton"
10-
import { useDebounce, useDeepCompareEffect } from "react-use"
1110
import { CREATE_HAI_RULES_PROMPT, HAI_RULES_PATH } from "../../utils/constants"
1211
import { TabButton } from "../mcp/McpView"
13-
import { useEvent } from "react-use"
14-
import { ExtensionMessage } from "../../../../src/shared/ExtensionMessage"
1512

1613
const 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

Comments
 (0)