diff --git a/services/web-ui/public/screens-library.jsx b/services/web-ui/public/screens-library.jsx index c5ea602..064968c 100644 --- a/services/web-ui/public/screens-library.jsx +++ b/services/web-ui/public/screens-library.jsx @@ -7,21 +7,24 @@ function Library({ navigate, onOpenAsset, openProject, onClearProject }) { // Re-fetch bins on mount + whenever the open project changes; surfaces // every-project bins when the global view is on, project-scoped otherwise. - React.useEffect(() => { - const qs = openProject ? '?project_id=' + openProject.id : ''; - window.ZAMPP_API.fetch('/bins' + qs) - .then(list => { - const normalized = (list || []).map(b => ({ - ...b, - count: b.asset_count != null ? b.asset_count : (b.count || 0), - icon: b.type || 'grid', - })); + var refreshBins = React.useCallback(function() { + var qs2 = openProject ? '?project_id=' + openProject.id : ''; + window.ZAMPP_API.fetch('/bins' + qs2) + .then(function(list) { + var normalized = (list || []).map(function(b) { return { ...b, count: b.asset_count != null ? b.asset_count : (b.count || 0), icon: b.type || 'grid' }; }); if (!openProject) window.ZAMPP_DATA.BINS = normalized; setBins(normalized); }) - .catch(() => {}); + .catch(function() {}); }, [openProject]); + React.useEffect(function() { + refreshBins(); + var onBinsChanged = function() { refreshBins(); }; + window.addEventListener('df:bins-changed', onBinsChanged); + return function() { window.removeEventListener('df:bins-changed', onBinsChanged); }; + }, [refreshBins]); + const createBin = () => { if (!openProject) { window.alert('Open a project first (Projects → click a project), then create a bin inside it.'); return; } setNewBinName(''); setCreatingBin(true); @@ -141,6 +144,7 @@ function Library({ navigate, onOpenAsset, openProject, onClearProject }) { .then(function() { setRecentlyMovedId(assetId); refreshAssets(); + window.dispatchEvent(new Event('df:bins-changed')); setTimeout(function() { setRecentlyMovedId(null); }, 2000); }) .catch(function(e2) { alert('Move failed: ' + e2.message); }); @@ -422,7 +426,7 @@ function AssetContextMenu({ asset, x, y, bins, onClose, onChanged, onOpen, onRen const moveToBin = function(binId) { onClose(); window.ZAMPP_API.fetch('/assets/' + asset.id, { method: 'PATCH', body: JSON.stringify({ bin_id: binId }) }) - .then(onChanged) + .then(function() { onChanged(); window.dispatchEvent(new Event('df:bins-changed')); }) .catch(function(e) { alert('Move failed: ' + e.message); }); };