add rescan button

This commit is contained in:
2026-05-16 14:39:00 -04:00
parent f23a8a2be6
commit b243266ad3
5 changed files with 157 additions and 39 deletions

View File

@@ -3,6 +3,7 @@ import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query";
import { api, type Library } from "../api/client";
function LibraryRow({ lib, onRemove }: { lib: Library; onRemove: (id: number) => void }) {
const qc = useQueryClient();
const { data } = useQuery({
queryKey: ["scan-status", lib.id],
queryFn: () => api.libraries.scanStatus(lib.id),
@@ -11,6 +12,11 @@ function LibraryRow({ lib, onRemove }: { lib: Library; onRemove: (id: number) =>
const scanning = data?.scanning ?? false;
const rescanMutation = useMutation({
mutationFn: () => api.libraries.rescan(lib.id),
onSuccess: () => qc.invalidateQueries({ queryKey: ["scan-status", lib.id] }),
});
return (
<li style={{ display: "flex", justifyContent: "space-between", alignItems: "center", padding: "8px 0", borderBottom: "1px solid var(--border-subtle)" }}>
<div>
@@ -22,13 +28,22 @@ function LibraryRow({ lib, onRemove }: { lib: Library; onRemove: (id: number) =>
)}
<div style={{ fontSize: 12, color: "var(--text-secondary)" }}>{lib.path}</div>
</div>
<button
onClick={() => onRemove(lib.id)}
disabled={scanning}
style={{ color: scanning ? "var(--text-muted)" : "var(--danger)", background: "transparent", border: "none" }}
>
Remove
</button>
<div style={{ display: "flex", gap: 8 }}>
<button
onClick={() => rescanMutation.mutate()}
disabled={scanning}
style={{ color: scanning ? "var(--text-muted)" : "var(--accent)", background: "transparent", border: "none" }}
>
Rescan
</button>
<button
onClick={() => onRemove(lib.id)}
disabled={scanning}
style={{ color: scanning ? "var(--text-muted)" : "var(--danger)", background: "transparent", border: "none" }}
>
Remove
</button>
</div>
</li>
);
}