mirror of
https://github.com/farion1231/cc-switch.git
synced 2026-07-27 16:26:16 +08:00
239c6fb2d7
The auto-open useEffect in CodexConfigEditor and GeminiConfigEditor created an inescapable loop: commonConfigError triggered modal open, closing the modal didn't clear the error, so the effect immediately reopened it — locking the entire UI. - Remove auto-open useEffect from both Codex and Gemini config editors - Convert common config modals to draft editing (edit locally, validate before save) instead of persisting on every keystroke - Add TOML/JSON pre-validation via parseCommonConfigSnippet before any merge operation to prevent invalid content from being persisted - Expose clearCommonConfigError so editors can clear stale errors on modal close
97 lines
2.3 KiB
TypeScript
97 lines
2.3 KiB
TypeScript
import React, { useState } from "react";
|
|
import { CodexAuthSection, CodexConfigSection } from "./CodexConfigSections";
|
|
import { CodexCommonConfigModal } from "./CodexCommonConfigModal";
|
|
|
|
interface CodexConfigEditorProps {
|
|
authValue: string;
|
|
|
|
configValue: string;
|
|
|
|
onAuthChange: (value: string) => void;
|
|
|
|
onConfigChange: (value: string) => void;
|
|
|
|
onAuthBlur?: () => void;
|
|
|
|
useCommonConfig: boolean;
|
|
|
|
onCommonConfigToggle: (checked: boolean) => void;
|
|
|
|
commonConfigSnippet: string;
|
|
|
|
onCommonConfigSnippetChange: (value: string) => boolean;
|
|
|
|
onCommonConfigErrorClear: () => void;
|
|
|
|
commonConfigError: string;
|
|
|
|
authError: string;
|
|
|
|
configError: string; // config.toml 错误提示
|
|
|
|
onExtract?: () => void;
|
|
|
|
isExtracting?: boolean;
|
|
}
|
|
|
|
const CodexConfigEditor: React.FC<CodexConfigEditorProps> = ({
|
|
authValue,
|
|
configValue,
|
|
onAuthChange,
|
|
onConfigChange,
|
|
onAuthBlur,
|
|
useCommonConfig,
|
|
onCommonConfigToggle,
|
|
commonConfigSnippet,
|
|
onCommonConfigSnippetChange,
|
|
onCommonConfigErrorClear,
|
|
commonConfigError,
|
|
authError,
|
|
configError,
|
|
onExtract,
|
|
isExtracting,
|
|
}) => {
|
|
const [isCommonConfigModalOpen, setIsCommonConfigModalOpen] = useState(false);
|
|
|
|
const handleCloseCommonConfigModal = () => {
|
|
onCommonConfigErrorClear();
|
|
setIsCommonConfigModalOpen(false);
|
|
};
|
|
|
|
return (
|
|
<div className="space-y-6">
|
|
{/* Auth JSON Section */}
|
|
<CodexAuthSection
|
|
value={authValue}
|
|
onChange={onAuthChange}
|
|
onBlur={onAuthBlur}
|
|
error={authError}
|
|
/>
|
|
|
|
{/* Config TOML Section */}
|
|
<CodexConfigSection
|
|
value={configValue}
|
|
onChange={onConfigChange}
|
|
useCommonConfig={useCommonConfig}
|
|
onCommonConfigToggle={onCommonConfigToggle}
|
|
onEditCommonConfig={() => setIsCommonConfigModalOpen(true)}
|
|
commonConfigError={commonConfigError}
|
|
configError={configError}
|
|
/>
|
|
|
|
{/* Common Config Modal */}
|
|
<CodexCommonConfigModal
|
|
isOpen={isCommonConfigModalOpen}
|
|
onClose={handleCloseCommonConfigModal}
|
|
value={commonConfigSnippet}
|
|
onSave={onCommonConfigSnippetChange}
|
|
error={commonConfigError}
|
|
onExtract={onExtract}
|
|
isExtracting={isExtracting}
|
|
/>
|
|
</div>
|
|
);
|
|
};
|
|
|
|
export default CodexConfigEditor;
|