fffiloni commited on
Commit
07798ed
·
verified ·
1 Parent(s): a8655d1

Upload 3 files

Browse files
Files changed (1) hide show
  1. static/app.js +17 -13
static/app.js CHANGED
@@ -55,6 +55,7 @@ const state = {
55
  libraryTags: [],
56
  librarySort: "created_desc",
57
  libraryLoading: false,
 
58
  libraryLoaded: false,
59
  libraryLoadingLabel: "",
60
  libraryProgressStartedAt: 0,
@@ -1284,7 +1285,7 @@ function renderLibraryProgress(options = {}) {
1284
  const panel = $("libraryProgressPanel");
1285
  if (!panel) return;
1286
  const isLibrary = state.reviewTab === "library";
1287
- const active = isLibrary && state.libraryLoading;
1288
  panel.hidden = !active;
1289
  if (!active) return;
1290
 
@@ -1338,13 +1339,15 @@ async function loadLibrary(options = {}) {
1338
  const requestSeq = (state.libraryRequestSeq || 0) + 1;
1339
  state.libraryRequestSeq = requestSeq;
1340
  state.libraryLoading = true;
 
1341
  state.libraryLoadingLabel = options.refresh
1342
  ? "Loading catalog from bucket…"
1343
  : (options.reason === "page" ? "Loading page…" : options.reason === "search" ? "Searching library…" : "Updating library…");
1344
  state.libraryMeta = { ...(state.libraryMeta || {}), offset: requestedOffset, limit: requestedLimit };
1345
  syncLibraryControls();
1346
- startLibraryProgress(options);
1347
- if (state.reviewTab === "library") {
 
1348
  renderReviewShell();
1349
  // Keep an active Library preview stable: the progress panel updates above
1350
  // the list, so we do not need to recreate rows just to show loading state.
@@ -1392,6 +1395,7 @@ async function loadLibrary(options = {}) {
1392
  } finally {
1393
  if (requestSeq === state.libraryRequestSeq) {
1394
  state.libraryLoading = false;
 
1395
  state.libraryLoadingLabel = "";
1396
  stopLibraryProgress();
1397
  if (state.reviewTab === "library") {
@@ -1430,9 +1434,9 @@ function syncLibraryControls() {
1430
  const page = Number(state.libraryMeta?.page || 0);
1431
  const pages = Number(state.libraryMeta?.pages || 0);
1432
  if (cacheChip) {
1433
- cacheChip.classList.toggle("ready", ready && !state.libraryLoading);
1434
- cacheChip.classList.toggle("loading", !!state.libraryLoading);
1435
- cacheChip.textContent = state.libraryLoading
1436
  ? "Updating…"
1437
  : ready ? `Cache hot · ${fmt.format(catalogCount || total)} tracks` : "Cache cold";
1438
  }
@@ -1449,8 +1453,8 @@ function syncLibraryControls() {
1449
  : "Load once to warm the shared 12h catalog cache.";
1450
  }
1451
  if (searchBtn) {
1452
- searchBtn.disabled = !!state.libraryLoading;
1453
- searchBtn.textContent = state.libraryLoading ? "Working…" : (state.librarySearchDirty ? "Search *" : "Search");
1454
  searchBtn.classList.toggle("attention", !!state.librarySearchDirty && !state.libraryLoading);
1455
  }
1456
  if (refresh) {
@@ -1458,7 +1462,7 @@ function syncLibraryControls() {
1458
  refresh.title = ready
1459
  ? "Force-reload the source bucket catalog. Normal searches and pagination do not need this."
1460
  : "Load the source bucket catalog into the shared Studio memory cache.";
1461
- refresh.disabled = !!state.libraryLoading;
1462
  }
1463
  }
1464
 
@@ -1508,7 +1512,7 @@ function renderLibraryPager() {
1508
  const end = Math.min(total, offset + state.library.length);
1509
  const page = Number(meta.page || (limit ? Math.floor(offset / limit) + 1 : 1));
1510
  const pages = Number(meta.pages || (limit ? Math.max(1, Math.ceil(total / limit)) : 1));
1511
- const busy = state.libraryLoading ? "disabled" : "";
1512
  const elapsed = Number(meta.elapsed_ms || 0);
1513
  const perf = elapsed ? ` · ${elapsed}ms${meta.normalized_cached ? " cached" : ""}` : "";
1514
  return `<div class="library-pager"><button class="btn small secondary" data-library-page="prev" ${busy || offset <= 0 ? "disabled" : ""} type="button">Previous</button><span>${start}-${end} of ${total} · page ${page}/${pages}${perf}</span><button class="btn small secondary" data-library-page="next" ${busy || offset + limit >= total ? "disabled" : ""} type="button">Next</button></div>`;
@@ -1604,7 +1608,7 @@ function renderDashboard(data, options = {}) {
1604
  // Library tab previously stored a cold-cache empty response. Force one
1605
  // cheap server query when the user is on Library so it does not stay empty.
1606
  if (state.reviewTab === "library" && (!wasCacheReady || !state.libraryLoaded) && !state.libraryLoading && !shouldFreezeLibraryRowsForAudio()) {
1607
- loadLibrary({ force: true, offset: 0 });
1608
  }
1609
  }
1610
 
@@ -1869,7 +1873,7 @@ function renderReviewRows() {
1869
  if (!rows.length) {
1870
  let empty = "No tracks found.";
1871
  if (state.reviewTab === "library") {
1872
- if (state.libraryLoading) empty = state.libraryLoadingLabel || "Loading Library…";
1873
  else if (state.libraryMeta?.last_error) empty = `Library unavailable: ${state.libraryMeta.last_error}`;
1874
  else if (!state.libraryMeta?.cache_ready) empty = "Catalog is not cached yet. Click Load catalog to refresh it from the bucket.";
1875
  else empty = "No library tracks match this search.";
@@ -1894,7 +1898,7 @@ function renderReviewRows() {
1894
  return;
1895
  }
1896
 
1897
- const libraryBusyOverlay = state.reviewTab === "library" && state.libraryLoading
1898
  ? `<div class="library-loading-overlay"><span class="spinner"></span><strong>${escapeHtml(state.libraryLoadingLabel || "Updating library…")}</strong></div>`
1899
  : "";
1900
  $("rotationRows").innerHTML = libraryBusyOverlay + (state.reviewTab === "library" ? renderLibraryPager() : "") + rows.map((t) => {
 
55
  libraryTags: [],
56
  librarySort: "created_desc",
57
  libraryLoading: false,
58
+ libraryLoadingVisible: false,
59
  libraryLoaded: false,
60
  libraryLoadingLabel: "",
61
  libraryProgressStartedAt: 0,
 
1285
  const panel = $("libraryProgressPanel");
1286
  if (!panel) return;
1287
  const isLibrary = state.reviewTab === "library";
1288
+ const active = isLibrary && state.libraryLoading && state.libraryLoadingVisible;
1289
  panel.hidden = !active;
1290
  if (!active) return;
1291
 
 
1339
  const requestSeq = (state.libraryRequestSeq || 0) + 1;
1340
  state.libraryRequestSeq = requestSeq;
1341
  state.libraryLoading = true;
1342
+ state.libraryLoadingVisible = !options.silent;
1343
  state.libraryLoadingLabel = options.refresh
1344
  ? "Loading catalog from bucket…"
1345
  : (options.reason === "page" ? "Loading page…" : options.reason === "search" ? "Searching library…" : "Updating library…");
1346
  state.libraryMeta = { ...(state.libraryMeta || {}), offset: requestedOffset, limit: requestedLimit };
1347
  syncLibraryControls();
1348
+ if (state.libraryLoadingVisible) startLibraryProgress(options);
1349
+ else renderLibraryProgress({ done: true });
1350
+ if (state.reviewTab === "library" && state.libraryLoadingVisible) {
1351
  renderReviewShell();
1352
  // Keep an active Library preview stable: the progress panel updates above
1353
  // the list, so we do not need to recreate rows just to show loading state.
 
1395
  } finally {
1396
  if (requestSeq === state.libraryRequestSeq) {
1397
  state.libraryLoading = false;
1398
+ state.libraryLoadingVisible = false;
1399
  state.libraryLoadingLabel = "";
1400
  stopLibraryProgress();
1401
  if (state.reviewTab === "library") {
 
1434
  const page = Number(state.libraryMeta?.page || 0);
1435
  const pages = Number(state.libraryMeta?.pages || 0);
1436
  if (cacheChip) {
1437
+ cacheChip.classList.toggle("ready", ready && !state.libraryLoadingVisible);
1438
+ cacheChip.classList.toggle("loading", !!state.libraryLoadingVisible);
1439
+ cacheChip.textContent = state.libraryLoadingVisible
1440
  ? "Updating…"
1441
  : ready ? `Cache hot · ${fmt.format(catalogCount || total)} tracks` : "Cache cold";
1442
  }
 
1453
  : "Load once to warm the shared 12h catalog cache.";
1454
  }
1455
  if (searchBtn) {
1456
+ searchBtn.disabled = !!state.libraryLoadingVisible;
1457
+ searchBtn.textContent = state.libraryLoadingVisible ? "Working…" : (state.librarySearchDirty ? "Search *" : "Search");
1458
  searchBtn.classList.toggle("attention", !!state.librarySearchDirty && !state.libraryLoading);
1459
  }
1460
  if (refresh) {
 
1462
  refresh.title = ready
1463
  ? "Force-reload the source bucket catalog. Normal searches and pagination do not need this."
1464
  : "Load the source bucket catalog into the shared Studio memory cache.";
1465
+ refresh.disabled = !!state.libraryLoadingVisible;
1466
  }
1467
  }
1468
 
 
1512
  const end = Math.min(total, offset + state.library.length);
1513
  const page = Number(meta.page || (limit ? Math.floor(offset / limit) + 1 : 1));
1514
  const pages = Number(meta.pages || (limit ? Math.max(1, Math.ceil(total / limit)) : 1));
1515
+ const busy = state.libraryLoadingVisible ? "disabled" : "";
1516
  const elapsed = Number(meta.elapsed_ms || 0);
1517
  const perf = elapsed ? ` · ${elapsed}ms${meta.normalized_cached ? " cached" : ""}` : "";
1518
  return `<div class="library-pager"><button class="btn small secondary" data-library-page="prev" ${busy || offset <= 0 ? "disabled" : ""} type="button">Previous</button><span>${start}-${end} of ${total} · page ${page}/${pages}${perf}</span><button class="btn small secondary" data-library-page="next" ${busy || offset + limit >= total ? "disabled" : ""} type="button">Next</button></div>`;
 
1608
  // Library tab previously stored a cold-cache empty response. Force one
1609
  // cheap server query when the user is on Library so it does not stay empty.
1610
  if (state.reviewTab === "library" && (!wasCacheReady || !state.libraryLoaded) && !state.libraryLoading && !shouldFreezeLibraryRowsForAudio()) {
1611
+ loadLibrary({ force: true, offset: 0, silent: true });
1612
  }
1613
  }
1614
 
 
1873
  if (!rows.length) {
1874
  let empty = "No tracks found.";
1875
  if (state.reviewTab === "library") {
1876
+ if (state.libraryLoadingVisible) empty = state.libraryLoadingLabel || "Loading Library…";
1877
  else if (state.libraryMeta?.last_error) empty = `Library unavailable: ${state.libraryMeta.last_error}`;
1878
  else if (!state.libraryMeta?.cache_ready) empty = "Catalog is not cached yet. Click Load catalog to refresh it from the bucket.";
1879
  else empty = "No library tracks match this search.";
 
1898
  return;
1899
  }
1900
 
1901
+ const libraryBusyOverlay = state.reviewTab === "library" && state.libraryLoadingVisible
1902
  ? `<div class="library-loading-overlay"><span class="spinner"></span><strong>${escapeHtml(state.libraryLoadingLabel || "Updating library…")}</strong></div>`
1903
  : "";
1904
  $("rotationRows").innerHTML = libraryBusyOverlay + (state.reviewTab === "library" ? renderLibraryPager() : "") + rows.map((t) => {