feat: Studio bulk ops, perf fixes, bug fixes, confirm dialog visibility
Confirm Dialog: - Overlay opacity 80% -> 95% (solid black) - Card uses bg-surface with glow shadow ring-primary/40 - Added AlertTriangle icon for danger variant - Removed backdrop-blur for maximum opacity Studio features: - Bulk delete: select imported items and delete in batch - Bulk nitro regen: select items missing .nitro and regenerate all - Added Trash2 and RefreshCw toolbar buttons for bulk actions Performance: - BatchProgress: React.memo + useMemo for entries/total/completed/percent - BatchProgress: ETA interval uses useRef to avoid re-creation per completed - CatalogRail: React.memo + useCallback for toggle - Removed redundant double setBatchProgress calls - Removed redundant new Map(initial) wrapping Bug fixes: - importBatch: stale batchDone closure always cleared progress panel (use ref) - importBatch: added missing toast.error on HTTP failure - bulkRegenNitro: now checks per-item results instead of marking all as succeeded - single deleteItem: now removes classname from selected set - retryFailed: clears progress panel on HTTP error and stream error - Removed unused 'done' variable (2x) from cloneAllMissing/retryFailed Lint: - biome format fixes for selectedMissingNitro and setItems
This commit is contained in:
1 parent
4863f78795
commit
93601e58e0
4 files changed
+214
-45
No files matched your search
@@ -1,7 +1,7 @@
|
||||
"use client";
|
||||
|
||||
import { Ban, Check, Loader2, ShieldCheck, X } from "lucide-react";
|
||||
import { useEffect, useState } from "react";
|
||||
import { memo, useEffect, useMemo, useRef, useState } from "react";
|
||||
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { cn } from "@/lib/utils";
|
||||
@@ -40,7 +40,7 @@ function formatEta(ms: number): string {
|
||||
return `${min}m ${sec}s`;
|
||||
}
|
||||
|
||||
export function BatchProgress({
|
||||
export const BatchProgress = memo(function BatchProgress({
|
||||
progress,
|
||||
done,
|
||||
succeeded,
|
||||
@@ -65,33 +65,42 @@ export function BatchProgress({
|
||||
onDismiss?: () => void;
|
||||
onRetry?: (classnames: string[]) => void;
|
||||
}) {
|
||||
const entries = [...progress.entries()];
|
||||
const total = entries.length;
|
||||
const completed = entries.filter(
|
||||
([, s]) => s.status === "done" || s.status === "failed",
|
||||
).length;
|
||||
const percent = total > 0 ? Math.round((completed / total) * 100) : 0;
|
||||
const { entries, total, completed, percent } = useMemo(() => {
|
||||
const e = [...progress.entries()];
|
||||
const t = e.length;
|
||||
const c = e.filter(
|
||||
([, s]) => s.status === "done" || s.status === "failed",
|
||||
).length;
|
||||
return {
|
||||
entries: e,
|
||||
total: t,
|
||||
completed: c,
|
||||
percent: t > 0 ? Math.round((c / t) * 100) : 0,
|
||||
};
|
||||
}, [progress]);
|
||||
|
||||
// Live ETA calculation
|
||||
const [eta, setEta] = useState<string | null>(null);
|
||||
const completedRef = useRef(completed);
|
||||
const totalRef = useRef(total);
|
||||
completedRef.current = completed;
|
||||
totalRef.current = total;
|
||||
|
||||
useEffect(() => {
|
||||
if (done || !startTime || completed === 0) {
|
||||
setEta(null);
|
||||
return;
|
||||
}
|
||||
const elapsed = Date.now() - startTime;
|
||||
const avgPerItem = elapsed / completed;
|
||||
const remaining = (total - completed) * avgPerItem;
|
||||
setEta(formatEta(remaining));
|
||||
|
||||
const interval = setInterval(() => {
|
||||
const calc = () => {
|
||||
const elapsed = Date.now() - startTime;
|
||||
const avgPerItem = elapsed / completed;
|
||||
const remaining = (total - completed) * avgPerItem;
|
||||
const avgPerItem = elapsed / completedRef.current;
|
||||
const remaining = (totalRef.current - completedRef.current) * avgPerItem;
|
||||
setEta(formatEta(remaining));
|
||||
}, 2000);
|
||||
};
|
||||
calc();
|
||||
const interval = setInterval(calc, 2000);
|
||||
return () => clearInterval(interval);
|
||||
}, [done, startTime, completed, total]);
|
||||
}, [done, startTime, completed]);
|
||||
|
||||
return (
|
||||
<div className="border-t border-[var(--admin-border)] p-3">
|
||||
@@ -244,4 +253,4 @@ export function BatchProgress({
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
});
|
||||
Reference in new issue
Block a user