q6 commited on
Commit
f68eccd
·
1 Parent(s): 9c29fe4

Defer scanned image loading

Browse files
Files changed (2) hide show
  1. frontend/app.js +26 -10
  2. frontend/index.html +2 -2
frontend/app.js CHANGED
@@ -79,7 +79,7 @@ function route() {
79
  if (tab === "explorer") {
80
  if (parts[1]) {
81
  closeExplorerEvents()
82
- openSearch(decodeURIComponent(parts[1]), parseInt(params.get("page")) || 1)
83
  } else {
84
  loadSearches(parseInt(params.get("page")) || 1)
85
  openExplorerEvents()
@@ -90,8 +90,8 @@ function route() {
90
  }
91
 
92
 
93
- function explorerHash(id, page) {
94
- return `#/explorer/${encodeURIComponent(id)}?page=${page}`
95
  }
96
 
97
 
@@ -219,14 +219,14 @@ function renderExifFilters(id) {
219
  if (action !== "submit") return
220
  const types = filters.filter(el => el.classList.contains("active")).map(el => Number(el.dataset.code))
221
  setExifTypes(types)
222
- const hash = explorerHash(id, 1)
223
- if (location.hash === hash) openSearch(id, 1)
224
  else location.hash = hash
225
  }
226
  })
227
  }
228
 
229
- async function openSearch(id, page = 1) {
230
  const list = $("#search-list")
231
  const detail = $("#search-detail")
232
  const exifTypes = getExifTypes()
@@ -237,6 +237,24 @@ async function openSearch(id, page = 1) {
237
  $("#pager").innerHTML = ""
238
  $("#results-grid").innerHTML = ""
239
  renderExifFilters(id)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
240
 
241
  try {
242
  const typesParam = exifTypes.length ? exifTypes.join(",") : "none"
@@ -246,7 +264,6 @@ async function openSearch(id, page = 1) {
246
 
247
  const allScanned = data.scanned_count >= data.raw_total
248
  $("#detail-stats").textContent = `${data.total}/${data.raw_total} shown | ${data.scanned_count}/${data.raw_total} scanned`
249
- const scanBtn = $("#btn-scan")
250
  scanBtn.textContent = allScanned ? "Scanned" : "Scan"
251
  scanBtn.disabled = allScanned
252
  scanBtn.onclick = async () => {
@@ -260,7 +277,6 @@ async function openSearch(id, page = 1) {
260
  }
261
  }
262
 
263
- $("#btn-back").onclick = () => { location.hash = "#/explorer" }
264
  renderPager(id, data)
265
  renderResults(data)
266
  } catch (e) {
@@ -404,8 +420,8 @@ function renderPager(id, data) {
404
  pager.innerHTML = `<button class="btn-secondary" id="page-prev" ${data.page <= 1 ? "disabled" : ""}>Prev</button>
405
  <span>${start}-${end} of ${data.total} | page ${data.page}/${data.pages}</span>
406
  <button class="btn-secondary" id="page-next" ${data.page >= data.pages ? "disabled" : ""}>Next</button>`
407
- $("#page-prev").onclick = () => { location.hash = explorerHash(id, prev) }
408
- $("#page-next").onclick = () => { location.hash = explorerHash(id, next) }
409
  }
410
 
411
  function esc(s) {
 
79
  if (tab === "explorer") {
80
  if (parts[1]) {
81
  closeExplorerEvents()
82
+ openSearch(decodeURIComponent(parts[1]), parseInt(params.get("page")) || 1, params.get("show") === "1")
83
  } else {
84
  loadSearches(parseInt(params.get("page")) || 1)
85
  openExplorerEvents()
 
90
  }
91
 
92
 
93
+ function explorerHash(id, page, show = false) {
94
+ return `#/explorer/${encodeURIComponent(id)}?page=${page}${show ? "&show=1" : ""}`
95
  }
96
 
97
 
 
219
  if (action !== "submit") return
220
  const types = filters.filter(el => el.classList.contains("active")).map(el => Number(el.dataset.code))
221
  setExifTypes(types)
222
+ const hash = explorerHash(id, 1, true)
223
+ if (location.hash === hash) openSearch(id, 1, true)
224
  else location.hash = hash
225
  }
226
  })
227
  }
228
 
229
+ async function openSearch(id, page = 1, show = false) {
230
  const list = $("#search-list")
231
  const detail = $("#search-detail")
232
  const exifTypes = getExifTypes()
 
237
  $("#pager").innerHTML = ""
238
  $("#results-grid").innerHTML = ""
239
  renderExifFilters(id)
240
+ $("#btn-back").onclick = () => { location.hash = "#/explorer" }
241
+ const scanBtn = $("#btn-scan")
242
+ scanBtn.textContent = "Scan"
243
+ scanBtn.disabled = false
244
+ scanBtn.onclick = async () => {
245
+ scanBtn.disabled = true
246
+ scanBtn.textContent = "Scanning"
247
+ try {
248
+ await resumeScan(id)
249
+ } catch {
250
+ scanBtn.disabled = false
251
+ scanBtn.textContent = "Scan"
252
+ }
253
+ }
254
+ if (!show) {
255
+ $("#detail-stats").textContent = "Submit to show results"
256
+ return
257
+ }
258
 
259
  try {
260
  const typesParam = exifTypes.length ? exifTypes.join(",") : "none"
 
264
 
265
  const allScanned = data.scanned_count >= data.raw_total
266
  $("#detail-stats").textContent = `${data.total}/${data.raw_total} shown | ${data.scanned_count}/${data.raw_total} scanned`
 
267
  scanBtn.textContent = allScanned ? "Scanned" : "Scan"
268
  scanBtn.disabled = allScanned
269
  scanBtn.onclick = async () => {
 
277
  }
278
  }
279
 
 
280
  renderPager(id, data)
281
  renderResults(data)
282
  } catch (e) {
 
420
  pager.innerHTML = `<button class="btn-secondary" id="page-prev" ${data.page <= 1 ? "disabled" : ""}>Prev</button>
421
  <span>${start}-${end} of ${data.total} | page ${data.page}/${data.pages}</span>
422
  <button class="btn-secondary" id="page-next" ${data.page >= data.pages ? "disabled" : ""}>Next</button>`
423
+ $("#page-prev").onclick = () => { location.hash = explorerHash(id, prev, true) }
424
+ $("#page-next").onclick = () => { location.hash = explorerHash(id, next, true) }
425
  }
426
 
427
  function esc(s) {
frontend/index.html CHANGED
@@ -5,7 +5,7 @@
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
  <link rel="icon" href="data:;base64,=">
7
  <title>Pixif2</title>
8
- <link rel="stylesheet" href="style.css?v=20260703-2">
9
  </head>
10
  <body>
11
  <div class="topbar">
@@ -77,6 +77,6 @@
77
  <img id="viewer-img" alt="">
78
  </div>
79
  </div>
80
- <script src="app.js?v=20260703-2"></script>
81
  </body>
82
  </html>
 
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
  <link rel="icon" href="data:;base64,=">
7
  <title>Pixif2</title>
8
+ <link rel="stylesheet" href="style.css?v=20260703-3">
9
  </head>
10
  <body>
11
  <div class="topbar">
 
77
  <img id="viewer-img" alt="">
78
  </div>
79
  </div>
80
+ <script src="app.js?v=20260703-3"></script>
81
  </body>
82
  </html>