Files
sofa/app/(pages)/settings/_components/update-check-section.tsx
T
jakeandClaude Opus 4.6 7a3052250d Optimize frontend: memoization, modern React hooks, reduced render overhead
- useTimeAgo: replace per-instance intervals with shared useSyncExternalStore ticker
- useTiltEffect: gate to fine-pointer devices, skip motion graphs on touch
- Carousel: bake WheelGesturesPlugin into primitive, remove from all consumers
- TitleSeasons: use memoized Set + precomputed progress map instead of Array.includes
- useSearch: stabilize results identity with useMemo
- CommandPalette: hoist shortcut grouping to module scope, stabilize effect deps
- StarRating: hoist static spring transition to module constant
- Settings toggles: use useOptimistic + useTransition for auto-rollback

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-06 16:15:08 -05:00

61 lines
1.8 KiB
TypeScript

"use client";
import { IconWorldUpload } from "@tabler/icons-react";
import { useOptimistic, useState, useTransition } from "react";
import { toast } from "sonner";
import { CardContent, CardDescription, CardTitle } from "@/components/ui/card";
import { Switch } from "@/components/ui/switch";
import { toggleUpdateCheck } from "@/lib/actions/settings";
export function UpdateCheckSection({
initialEnabled,
}: {
initialEnabled: boolean;
}) {
const [enabled, setEnabled] = useState(initialEnabled);
const [optimisticEnabled, setOptimisticEnabled] = useOptimistic(enabled);
const [isPending, startTransition] = useTransition();
function handleToggle(checked: boolean) {
startTransition(async () => {
setOptimisticEnabled(checked);
try {
await toggleUpdateCheck(checked);
setEnabled(checked);
toast.success(
checked ? "Update checks enabled" : "Update checks disabled",
);
} catch {
toast.error("Failed to update setting");
}
});
}
return (
<CardContent>
<div className="flex items-center justify-between gap-4">
<div className="flex items-start gap-3">
<div className="mt-0.5 flex h-8 w-8 shrink-0 items-center justify-center rounded-lg bg-primary/10">
<IconWorldUpload
aria-hidden={true}
className="size-4 text-primary"
/>
</div>
<div>
<CardTitle>Automatic update checks</CardTitle>
<CardDescription>
Periodically check GitHub for new Sofa releases
</CardDescription>
</div>
</div>
<Switch
checked={optimisticEnabled}
onCheckedChange={handleToggle}
disabled={isPending}
aria-label="Toggle automatic update checks"
/>
</div>
</CardContent>
);
}