fix(ui): LibraryActions checkbox values and error handling

This commit is contained in:
2026-03-06 14:14:21 +01:00
parent d001e29bbc
commit 323661f770

View File

@@ -35,21 +35,32 @@ export function LibraryActions({
const handleSubmit = (formData: FormData) => { const handleSubmit = (formData: FormData) => {
startTransition(async () => { startTransition(async () => {
const data = { const monitorEnabled = formData.get("monitor_enabled") === "true";
monitor_enabled: formData.get("monitor_enabled") === "true", const watcherEnabled = formData.get("watcher_enabled") === "true";
scan_mode: formData.get("scan_mode") as string, const scanMode = formData.get("scan_mode") as string;
watcher_enabled: formData.get("watcher_enabled") === "true",
};
await fetch(`/api/libraries/${libraryId}/monitoring`, { try {
const response = await fetch(`/api/libraries/${libraryId}/monitoring`, {
method: "PATCH", method: "PATCH",
headers: { "Content-Type": "application/json" }, headers: { "Content-Type": "application/json" },
body: JSON.stringify(data), body: JSON.stringify({
monitor_enabled: monitorEnabled,
scan_mode: scanMode,
watcher_enabled: watcherEnabled,
}),
}); });
if (response.ok) {
setIsOpen(false); setIsOpen(false);
onUpdate?.();
window.location.reload(); window.location.reload();
} else {
console.error("Failed to save settings:", response.statusText);
alert("Failed to save settings. Please try again.");
}
} catch (error) {
console.error("Failed to save settings:", error);
alert("Failed to save settings. Please try again.");
}
}); });
}; };
@@ -69,23 +80,29 @@ export function LibraryActions({
<form action={handleSubmit}> <form action={handleSubmit}>
<div className="space-y-4"> <div className="space-y-4">
<div className="flex items-center justify-between"> <div className="flex items-center justify-between">
<label className="text-sm font-medium text-foreground">🔄 Auto Scan</label> <label className="text-sm font-medium text-foreground flex items-center gap-2">
<input <input
type="checkbox" type="checkbox"
name="monitor_enabled" name="monitor_enabled"
value="true"
defaultChecked={monitorEnabled} defaultChecked={monitorEnabled}
className="w-4 h-4 rounded border-line text-primary focus:ring-primary" className="w-4 h-4 rounded border-line text-primary focus:ring-primary"
/> />
Auto Scan
</label>
</div> </div>
<div className="flex items-center justify-between"> <div className="flex items-center justify-between">
<label className="text-sm font-medium text-foreground"> File Watcher</label> <label className="text-sm font-medium text-foreground flex items-center gap-2">
<input <input
type="checkbox" type="checkbox"
name="watcher_enabled" name="watcher_enabled"
value="true"
defaultChecked={watcherEnabled} defaultChecked={watcherEnabled}
className="w-4 h-4 rounded border-line text-primary focus:ring-primary" className="w-4 h-4 rounded border-line text-primary focus:ring-primary"
/> />
File Watcher
</label>
</div> </div>
<div className="flex items-center justify-between"> <div className="flex items-center justify-between">