Auto refresh library after ingest
This commit is contained in:
parent
78539ec8b0
commit
c501d88c63
1 changed files with 6 additions and 10 deletions
|
|
@ -60,26 +60,22 @@ function Library({ navigate, onOpenAsset, openProject, onClearProject }) {
|
||||||
const [projVersion, setProjVersion] = React.useState(0);
|
const [projVersion, setProjVersion] = React.useState(0);
|
||||||
|
|
||||||
const refreshAssets = React.useCallback(() => {
|
const refreshAssets = React.useCallback(() => {
|
||||||
window.ZAMPP_API.fetch('/assets?limit=500')
|
window.ZAMPP_API.refreshAssets()
|
||||||
.then(r => {
|
.then(function(normalized) {
|
||||||
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;
|
|
||||||
setAllAssets(normalized);
|
setAllAssets(normalized);
|
||||||
})
|
})
|
||||||
.catch(() => {});
|
.catch(() => {});
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
// Auto-refresh: poll the library while it's open so live recordings flip
|
// Auto-refresh: poll the library while it's open so live recordings flip
|
||||||
// to 'ready' (with thumbnail) without a manual reload. Speed up while
|
// to 'ready' (with thumbnail) without a manual reload. Also pull once on
|
||||||
// anything is mid-flight so the operator sees the transition right away.
|
// mount so uploads/imports created on other screens appear immediately.
|
||||||
const hasLive = React.useMemo(
|
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]
|
[allAssets]
|
||||||
);
|
);
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
|
refreshAssets();
|
||||||
const tick = hasLive ? 4000 : 15000;
|
const tick = hasLive ? 4000 : 15000;
|
||||||
const id = setInterval(refreshAssets, tick);
|
const id = setInterval(refreshAssets, tick);
|
||||||
const onAssetsChanged = () => refreshAssets();
|
const onAssetsChanged = () => refreshAssets();
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue