fix(ui): LibraryActions checkbox values and error handling
This commit is contained in:
@@ -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 {
|
||||||
method: "PATCH",
|
const response = await fetch(`/api/libraries/${libraryId}/monitoring`, {
|
||||||
headers: { "Content-Type": "application/json" },
|
method: "PATCH",
|
||||||
body: JSON.stringify(data),
|
headers: { "Content-Type": "application/json" },
|
||||||
});
|
body: JSON.stringify({
|
||||||
|
monitor_enabled: monitorEnabled,
|
||||||
|
scan_mode: scanMode,
|
||||||
|
watcher_enabled: watcherEnabled,
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
|
||||||
setIsOpen(false);
|
if (response.ok) {
|
||||||
onUpdate?.();
|
setIsOpen(false);
|
||||||
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"
|
||||||
defaultChecked={monitorEnabled}
|
value="true"
|
||||||
className="w-4 h-4 rounded border-line text-primary focus:ring-primary"
|
defaultChecked={monitorEnabled}
|
||||||
/>
|
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"
|
||||||
defaultChecked={watcherEnabled}
|
value="true"
|
||||||
className="w-4 h-4 rounded border-line text-primary focus:ring-primary"
|
defaultChecked={watcherEnabled}
|
||||||
/>
|
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">
|
||||||
|
|||||||
Reference in New Issue
Block a user