mirror of
https://github.com/farion1231/cc-switch.git
synced 2026-03-22 15:08:22 +08:00
fix(provider-form): reset baseUrl and apiKey states when switching presets
Fix state synchronization in useBaseUrlState and useApiKeyState hooks to properly clear values when config is reset. Previously, when switching from a preset to "custom", the baseUrl and apiKey states would retain their old values because the sync logic only updated when new values existed, not when they were cleared. Changes: - useBaseUrlState: Always sync baseUrl to config value (empty if undefined) - useApiKeyState: Remove hasApiKeyField check that prevented clearing
This commit is contained in:
@@ -43,11 +43,7 @@ export function useApiKeyState({
|
||||
return;
|
||||
}
|
||||
|
||||
// 仅当配置确实包含 API Key 字段时才同步(避免无意清空用户正在输入的 key)
|
||||
if (!hasApiKeyField(initialConfig, appType)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 从配置中提取 API Key(如果不存在则返回空字符串)
|
||||
const extracted = getApiKeyFromConfig(initialConfig, appType);
|
||||
if (extracted !== apiKey) {
|
||||
setApiKey(extracted);
|
||||
|
||||
@@ -41,8 +41,9 @@ export function useBaseUrlState({
|
||||
try {
|
||||
const config = JSON.parse(settingsConfig || "{}");
|
||||
const envUrl: unknown = config?.env?.ANTHROPIC_BASE_URL;
|
||||
if (typeof envUrl === "string" && envUrl && envUrl.trim() !== baseUrl) {
|
||||
setBaseUrl(envUrl.trim());
|
||||
const nextUrl = typeof envUrl === "string" ? envUrl.trim() : "";
|
||||
if (nextUrl !== baseUrl) {
|
||||
setBaseUrl(nextUrl);
|
||||
}
|
||||
} catch {
|
||||
// ignore
|
||||
|
||||
Reference in New Issue
Block a user