Feature/293 remove backgrounds from inventory #296

Merged
bermudalamb merged 9 commits from feature/293-remove-backgrounds-from-inventory into main 2026-09-04 12:20:01 -05:00
Showing only changes of commit dbb63bc3d2 - Show all commits
+16 -9
View File
@@ -85,11 +85,15 @@ function Inventory() {
return fetchAdminItems(active) return fetchAdminItems(active)
.then(rows => { .then(rows => {
if (seq === latestRequest.current) setItems(rows); if (seq === latestRequest.current) setItems(rows);
// Handed back so a caller that needs one fresh row (handleBackgrounds)
// can pick it out of this filtered fetch instead of issuing its own
// second, unfiltered one.
return rows;
}) })
// Without this the table simply keeps showing whatever it had, so a // Without this the table simply keeps showing whatever it had, so a
// failed refetch after a save looks identical to a save that did not // failed refetch after a save looks identical to a save that did not
// change anything. // change anything.
.catch(() => message.error('Could not load items')); .catch(() => { message.error('Could not load items'); return undefined; });
}, [filters]); }, [filters]);
// The item form needs the current category tree and tag list; both change // The item form needs the current category tree and tag list; both change
@@ -213,6 +217,7 @@ function Inventory() {
* showing the previous files and the button looks like it did nothing. * showing the previous files and the button looks like it did nothing.
*/ */
async function handleBackgrounds(itemId: number, action: 'remove-backgrounds' | 'restore-originals') { async function handleBackgrounds(itemId: number, action: 'remove-backgrounds' | 'restore-originals') {
const label = action === 'remove-backgrounds' ? 'remove backgrounds' : 'restore originals';
setBusyBackgrounds(true); setBusyBackgrounds(true);
try { try {
const res = await fetch(`/api/admin/items/${itemId}/${action}`, { method: 'POST' }); const res = await fetch(`/api/admin/items/${itemId}/${action}`, { method: 'POST' });
@@ -231,14 +236,16 @@ function Inventory() {
message.success('Done.'); message.success('Done.');
} }
// Re-read the item so the thumbnails match what is now on the server. // Re-read the list through load() — same as every other mutation here —
const fresh = await fetch('/api/admin/items'); // so a filtered view survives this, then pick this item's fresh images
if (fresh.ok) { // back out of it for the open modal. The item's own filtered fields
const all: Item[] = await fresh.json(); // (category, tags, status, search) are untouched by a background swap,
const updated = all.find((candidate) => candidate.id === itemId); // so it stays in the result whenever it was in it before.
if (updated) setEditingItem(prev => (prev && prev.id === itemId ? updated : prev)); const rows = await load();
setItems(all); const updated = rows?.find(candidate => candidate.id === itemId);
} if (updated) setEditingItem(prev => (prev && prev.id === itemId ? updated : prev));
} catch (err) {
message.error(`Couldn't ${label}${(err as Error).message}`);
} finally { } finally {
setBusyBackgrounds(false); setBusyBackgrounds(false);
} }