q6 commited on
Commit
67bc7a3
·
1 Parent(s): 9a6314c

Keep explorer filter counts during reload

Browse files
Files changed (2) hide show
  1. frontend/app.js +19 -3
  2. frontend/index.html +1 -1
frontend/app.js CHANGED
@@ -372,14 +372,16 @@ function renderCategoryFilters(root) {
372
  }
373
 
374
  function renderExifFilters(id, submitted = false, counts = null) {
375
- if (counts) exifCountsCache.set(id, counts)
376
- const shownCounts = counts || exifCountsCache.get(id)
377
  const active = new Set(getExifTypes())
378
  const buttons = FILTER_CODES.map(code => {
379
  const count = shownCounts ? ` (${shownCounts[code] || 0})` : ""
380
  return `<button class="filter-btn${active.has(code) ? " active" : ""}" data-code="${code}">${esc(CATEGORY_NAMES[code])}${count}</button>`
381
  }).join("")
382
- $("#exif-filters").innerHTML = `${buttons}
 
 
383
  <button class="filter-action" data-action="all">Select all</button>
384
  <button class="filter-action" data-action="none">Select none</button>
385
  <button class="filter-action submit" data-action="submit">${submitted ? "Update" : "Submit"}</button>`
@@ -407,6 +409,20 @@ function renderExifFilters(id, submitted = false, counts = null) {
407
  })
408
  }
409
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
410
  async function openSearch(id, page = 1, show = false, view = explorerDetailView(id, page, show)) {
411
  currentExplorerView = null
412
  loadedExplorerListPage = null
 
372
  }
373
 
374
  function renderExifFilters(id, submitted = false, counts = null) {
375
+ const shownCounts = counts ?? exifCountsCache.get(id) ?? visibleExifCounts(id)
376
+ if (shownCounts) exifCountsCache.set(id, shownCounts)
377
  const active = new Set(getExifTypes())
378
  const buttons = FILTER_CODES.map(code => {
379
  const count = shownCounts ? ` (${shownCounts[code] || 0})` : ""
380
  return `<button class="filter-btn${active.has(code) ? " active" : ""}" data-code="${code}">${esc(CATEGORY_NAMES[code])}${count}</button>`
381
  }).join("")
382
+ const root = $("#exif-filters")
383
+ root.dataset.id = id
384
+ root.innerHTML = `${buttons}
385
  <button class="filter-action" data-action="all">Select all</button>
386
  <button class="filter-action" data-action="none">Select none</button>
387
  <button class="filter-action submit" data-action="submit">${submitted ? "Update" : "Submit"}</button>`
 
409
  })
410
  }
411
 
412
+ function visibleExifCounts(id) {
413
+ const root = $("#exif-filters")
414
+ if (root.dataset.id !== id) return null
415
+ const counts = {}
416
+ let found = false
417
+ $$("#exif-filters .filter-btn").forEach(btn => {
418
+ const match = btn.textContent.match(/\((\d+)\)$/)
419
+ if (!match) return
420
+ counts[Number(btn.dataset.code)] = Number(match[1])
421
+ found = true
422
+ })
423
+ return found ? counts : null
424
+ }
425
+
426
  async function openSearch(id, page = 1, show = false, view = explorerDetailView(id, page, show)) {
427
  currentExplorerView = null
428
  loadedExplorerListPage = null
frontend/index.html CHANGED
@@ -109,6 +109,6 @@
109
  <img id="viewer-img" alt="">
110
  </div>
111
  </div>
112
- <script src="app.js?v=20260704-2"></script>
113
  </body>
114
  </html>
 
109
  <img id="viewer-img" alt="">
110
  </div>
111
  </div>
112
+ <script src="app.js?v=20260704-3"></script>
113
  </body>
114
  </html>