add rescan button
This commit is contained in:
@@ -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>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user