fix: show restore defaults only on General settings (#1710)

This commit is contained in:
Utkarsh Patil authored and GitHub committed 2026-04-17 13:49:18 -07:00
1 parent ce94feeea1
commit 60387f67e9
1 file changed
+32 -28
+32 -28
View File
@@ -1,5 +1,5 @@
import { RotateCcwIcon } from "lucide-react";
import { Outlet, createFileRoute, redirect } from "@tanstack/react-router";
import { Outlet, createFileRoute, redirect, useLocation } from "@tanstack/react-router";
import { useEffect, useState } from "react";
import { useSettingsRestore } from "../components/settings/SettingsPanels";
@@ -7,11 +7,27 @@ import { Button } from "../components/ui/button";
import { SidebarInset, SidebarTrigger } from "../components/ui/sidebar";
import { isElectron } from "../env";
function SettingsContentLayout() {
const [restoreSignal, setRestoreSignal] = useState(0);
const { changedSettingLabels, restoreDefaults } = useSettingsRestore(() =>
setRestoreSignal((value) => value + 1),
function RestoreDefaultsButton({ onRestored }: { onRestored: () => void }) {
const { changedSettingLabels, restoreDefaults } = useSettingsRestore(onRestored);
return (
<Button
size="xs"
variant="outline"
disabled={changedSettingLabels.length === 0}
onClick={() => void restoreDefaults()}
>
<RotateCcwIcon className="size-3.5" />
Restore defaults
</Button>
);
}
function SettingsContentLayout() {
const location = useLocation();
const [restoreSignal, setRestoreSignal] = useState(0);
const showRestoreDefaults = location.pathname === "/settings/general";
const handleRestored = () => setRestoreSignal((value) => value + 1);
useEffect(() => {
const onKeyDown = (event: KeyboardEvent) => {
@@ -33,20 +49,14 @@ function SettingsContentLayout() {
<div className="flex min-h-0 min-w-0 flex-1 flex-col bg-background text-foreground">
{!isElectron && (
<header className="border-b border-border px-3 py-2 sm:px-5">
<div className="flex items-center gap-2">
<div className="flex min-h-7 items-center gap-2 sm:min-h-6">
<SidebarTrigger className="size-7 shrink-0 md:hidden" />
<span className="text-sm font-medium text-foreground">Settings</span>
<div className="ms-auto flex items-center gap-2">
<Button
size="xs"
variant="outline"
disabled={changedSettingLabels.length === 0}
onClick={() => void restoreDefaults()}
>
<RotateCcwIcon className="size-3.5" />
Restore defaults
</Button>
</div>
{showRestoreDefaults ? (
<div className="ms-auto flex items-center gap-2">
<RestoreDefaultsButton onRestored={handleRestored} />
</div>
) : null}
</div>
</header>
)}
@@ -56,17 +66,11 @@ function SettingsContentLayout() {
<span className="text-xs font-medium tracking-wide text-muted-foreground/70">
Settings
</span>
<div className="ms-auto flex items-center gap-2">
<Button
size="xs"
variant="outline"
disabled={changedSettingLabels.length === 0}
onClick={() => void restoreDefaults()}
>
<RotateCcwIcon className="size-3.5" />
Restore defaults
</Button>
</div>
{showRestoreDefaults ? (
<div className="ms-auto flex items-center gap-2">
<RestoreDefaultsButton onRestored={handleRestored} />
</div>
) : null}
</div>
)}