style: format frontend code and improve component structure

This commit is contained in:
Jason
2025-09-05 21:26:01 +08:00
parent da4f7b5fe4
commit 37d4c9b48d
4 changed files with 39 additions and 21 deletions

View File

@@ -179,10 +179,7 @@ function App() {
<header className="app-header"> <header className="app-header">
<h1>CC Switch</h1> <h1>CC Switch</h1>
<div className="app-tabs"> <div className="app-tabs">
<AppSwitcher <AppSwitcher activeApp={activeApp} onSwitch={setActiveApp} />
activeApp={activeApp}
onSwitch={setActiveApp}
/>
</div> </div>
<div className="header-actions"> <div className="header-actions">
<button className="add-btn" onClick={() => setIsAddModalOpen(true)}> <button className="add-btn" onClick={() => setIsAddModalOpen(true)}>

View File

@@ -34,7 +34,7 @@
.switcher-pill.active { .switcher-pill.active {
background: rgba(255, 255, 255, 0.15); background: rgba(255, 255, 255, 0.15);
color: white; color: white;
box-shadow: box-shadow:
inset 0 1px 3px rgba(0, 0, 0, 0.1), inset 0 1px 3px rgba(0, 0, 0, 0.1),
0 1px 0 rgba(255, 255, 255, 0.1); 0 1px 0 rgba(255, 255, 255, 0.1);
} }
@@ -61,6 +61,13 @@
} }
@keyframes pulse { @keyframes pulse {
0%, 100% { transform: scale(1); opacity: 1; } 0%,
50% { transform: scale(1.2); opacity: 0.8; } 100% {
} transform: scale(1);
opacity: 1;
}
50% {
transform: scale(1.2);
opacity: 0.8;
}
}

View File

@@ -33,4 +33,4 @@ export function AppSwitcher({ activeApp, onSwitch }: AppSwitcherProps) {
</button> </button>
</div> </div>
); );
} }

View File

@@ -74,7 +74,7 @@ const ProviderForm: React.FC<ProviderFormProps> = ({
const [disableCoAuthored, setDisableCoAuthored] = useState(false); const [disableCoAuthored, setDisableCoAuthored] = useState(false);
// -1 表示自定义null 表示未选择,>= 0 表示预设索引 // -1 表示自定义null 表示未选择,>= 0 表示预设索引
const [selectedPreset, setSelectedPreset] = useState<number | null>( const [selectedPreset, setSelectedPreset] = useState<number | null>(
showPresets ? -1 : null showPresets ? -1 : null,
); );
const [apiKey, setApiKey] = useState(""); const [apiKey, setApiKey] = useState("");
@@ -302,7 +302,7 @@ const ProviderForm: React.FC<ProviderFormProps> = ({
// 根据当前配置决定是否展示 API Key 输入框 // 根据当前配置决定是否展示 API Key 输入框
// 自定义模式(-1)不显示独立的 API Key 输入框 // 自定义模式(-1)不显示独立的 API Key 输入框
const showApiKey = const showApiKey =
(selectedPreset !== null && selectedPreset !== -1) || (selectedPreset !== null && selectedPreset !== -1) ||
(!showPresets && hasApiKeyField(formData.settingsConfig)); (!showPresets && hasApiKeyField(formData.settingsConfig));
// 判断当前选中的预设是否是官方 // 判断当前选中的预设是否是官方
@@ -322,7 +322,7 @@ const ProviderForm: React.FC<ProviderFormProps> = ({
}; };
// 自定义模式(-1)不显示独立的 API Key 输入框 // 自定义模式(-1)不显示独立的 API Key 输入框
const showCodexApiKey = const showCodexApiKey =
(selectedCodexPreset !== null && selectedCodexPreset !== -1) || (selectedCodexPreset !== null && selectedCodexPreset !== -1) ||
(!showPresets && getCodexAuthApiKey(codexAuth) !== ""); (!showPresets && getCodexAuthApiKey(codexAuth) !== "");
const isCodexOfficialPreset = const isCodexOfficialPreset =
selectedCodexPreset !== null && selectedCodexPreset !== null &&
@@ -409,14 +409,20 @@ const ProviderForm: React.FC<ProviderFormProps> = ({
})} })}
</div> </div>
{selectedPreset === -1 && ( {selectedPreset === -1 && (
<small className="field-hint" style={{ marginTop: "8px", display: "block" }}> <small
className="field-hint"
style={{ marginTop: "8px", display: "block" }}
>
</small> </small>
)} )}
{selectedPreset !== -1 && selectedPreset !== null && ( {selectedPreset !== -1 && selectedPreset !== null && (
<small className="field-hint" style={{ marginTop: "8px", display: "block" }}> <small
{isOfficialPreset className="field-hint"
? "Claude 官方登录,不需要填写 API Key" style={{ marginTop: "8px", display: "block" }}
>
{isOfficialPreset
? "Claude 官方登录,不需要填写 API Key"
: "使用预设配置,只需填写 API Key"} : "使用预设配置,只需填写 API Key"}
</small> </small>
)} )}
@@ -450,14 +456,20 @@ const ProviderForm: React.FC<ProviderFormProps> = ({
))} ))}
</div> </div>
{selectedCodexPreset === -1 && ( {selectedCodexPreset === -1 && (
<small className="field-hint" style={{ marginTop: "8px", display: "block" }}> <small
className="field-hint"
style={{ marginTop: "8px", display: "block" }}
>
</small> </small>
)} )}
{selectedCodexPreset !== -1 && selectedCodexPreset !== null && ( {selectedCodexPreset !== -1 && selectedCodexPreset !== null && (
<small className="field-hint" style={{ marginTop: "8px", display: "block" }}> <small
{isCodexOfficialPreset className="field-hint"
? "Codex 官方登录,不需要填写 API Key" style={{ marginTop: "8px", display: "block" }}
>
{isCodexOfficialPreset
? "Codex 官方登录,不需要填写 API Key"
: "使用预设配置,只需填写 API Key"} : "使用预设配置,只需填写 API Key"}
</small> </small>
)} )}
@@ -525,7 +537,9 @@ const ProviderForm: React.FC<ProviderFormProps> = ({
} }
disabled={isCodexOfficialPreset} disabled={isCodexOfficialPreset}
required={ required={
selectedCodexPreset !== null && selectedCodexPreset >= 0 && !isCodexOfficialPreset selectedCodexPreset !== null &&
selectedCodexPreset >= 0 &&
!isCodexOfficialPreset
} }
autoComplete="off" autoComplete="off"
style={ style={