Auto refresh library after ingest

This commit is contained in:
Zac Gaetano 2026-05-25 01:13:19 -04:00
parent 78539ec8b0
commit c501d88c63

View file

@ -60,26 +60,22 @@ function Library({ navigate, onOpenAsset, openProject, onClearProject }) {
const [projVersion, setProjVersion] = React.useState(0);
const refreshAssets = React.useCallback(() => {
window.ZAMPP_API.fetch('/assets?limit=500')
.then(r => {
const list = Array.isArray(r) ? r : (r.assets || []);
const proj = {};
(window.ZAMPP_DATA?.PROJECTS || []).forEach(p => { proj[p.id] = p.name; });
const normalized = list.map(a => window.normalizeAsset ? window.normalizeAsset(a, proj) : a);
window.ZAMPP_DATA.ASSETS = normalized;
window.ZAMPP_API.refreshAssets()
.then(function(normalized) {
setAllAssets(normalized);
})
.catch(() => {});
}, []);
// Auto-refresh: poll the library while it's open so live recordings flip
// to 'ready' (with thumbnail) without a manual reload. Speed up while
// anything is mid-flight so the operator sees the transition right away.
// to 'ready' (with thumbnail) without a manual reload. Also pull once on
// mount so uploads/imports created on other screens appear immediately.
const hasLive = React.useMemo(
() => allAssets.some(a => a.status === 'live' || a.status === 'processing'),
() => allAssets.some(a => a.status === 'live' || a.status === 'processing' || a.status === 'ingesting'),
[allAssets]
);
React.useEffect(() => {
refreshAssets();
const tick = hasLive ? 4000 : 15000;
const id = setInterval(refreshAssets, tick);
const onAssetsChanged = () => refreshAssets();