diff --git a/src/components/settings/version-control-settings.tsx b/src/components/settings/version-control-settings.tsx index 4dac697..84d7611 100644 --- a/src/components/settings/version-control-settings.tsx +++ b/src/components/settings/version-control-settings.tsx @@ -7,7 +7,6 @@ import { Github, Globe, Loader2, - Save, Trash2, XCircle, } from "lucide-react" @@ -152,9 +151,8 @@ export function VersionControlSettings() { const [loading, setLoading] = useState(true) const [gitInfo, setGitInfo] = useState(null) const [customPath, setCustomPath] = useState("") + const [editingPath, setEditingPath] = useState(false) const [savingGit, setSavingGit] = useState(false) - const [testingGit, setTestingGit] = useState(false) - const [testResult, setTestResult] = useState(null) const [accounts, setAccounts] = useState({ accounts: [], @@ -197,34 +195,24 @@ export function VersionControlSettings() { loadData().catch(console.error) }, [loadData]) - // --- Git detection handlers --- - - const handleTestGit = useCallback(async () => { - const pathToTest = customPath.trim() || "git" - setTestingGit(true) - setTestResult(null) - try { - const result = await testGitPath(pathToTest) - setTestResult(result) - if (result.installed) { - toast.success(t("testSuccess")) - } else { - toast.error(t("testFailed", { message: "not a valid git executable" })) - } - } catch (err) { - const message = err instanceof Error ? err.message : String(err) - toast.error(t("testFailed", { message })) - } finally { - setTestingGit(false) - } - }, [customPath, t]) + // --- Git path handlers --- const handleSaveGit = useCallback(async () => { + const trimmed = customPath.trim() setSavingGit(true) try { - await updateGitSettings({ custom_path: customPath.trim() || null }) + // Test first if a custom path is provided + if (trimmed) { + const result = await testGitPath(trimmed) + if (!result.installed) { + toast.error(t("testFailed", { message: "not a valid git executable" })) + return + } + } + await updateGitSettings({ custom_path: trimmed || null }) const git = await detectGit() setGitInfo(git) + setEditingPath(false) toast.success(t("saveSuccess")) } catch (err) { const message = err instanceof Error ? err.message : String(err) @@ -234,6 +222,14 @@ export function VersionControlSettings() { } }, [customPath, t]) + const handleCancelEdit = useCallback(() => { + setEditingPath(false) + // Restore to the saved value + getGitSettings() + .then((s) => setCustomPath(s.custom_path ?? "")) + .catch(() => {}) + }, []) + // --- Shared account handlers --- const handleAccountAdded = useCallback( @@ -355,33 +351,42 @@ export function VersionControlSettings() {

{t("gitTitle")}

-

- {t("gitDescription")} -

-
- {gitInfo?.installed ? ( - <> - - - {t("gitDetected")} +
+
+ {gitInfo?.installed ? ( + <> + + + {t("gitDetected")} + + + ) : ( + <> + + + {t("gitNotFound")} + + + )} + {gitInfo?.version && ( + + {gitInfo.version} - - ) : ( - <> - - - {t("gitNotFound")} - - + )} +
+ {!editingPath && ( + )}
- {gitInfo?.version && ( -

- {t("gitVersion")}: {gitInfo.version} -

- )} {gitInfo?.path && (

{t("gitPath")}: {gitInfo.path} @@ -389,74 +394,44 @@ export function VersionControlSettings() { )}

-
- -
- { - setCustomPath(e.target.value) - setTestResult(null) - }} - placeholder={t("customGitPathPlaceholder")} - className="flex-1" - /> - + -
-

- {t("customGitPathHint")} -

- {testResult && ( -
- {testResult.installed ? ( - - ) : ( - - )} - {testResult.installed - ? `${t("testSuccess")} (${testResult.version})` - : t("testFailed", { message: "invalid" })} + ) : ( + t("save") + )} +
- )} -
- -
- -
+

+ {t("customGitPathHint")} +

+
+ )} {/* ---- GitHub Accounts ---- */}