mozilla/pdf.js
This commit is contained in:
13
web/app.js
13
web/app.js
@@ -1,6 +1,7 @@
|
||||
let state;
|
||||
let groups = [];
|
||||
let selectedIndex = -1;
|
||||
let loadedIndex = -1; // which document the PDF viewer currently shows/loads
|
||||
let pdfViewer = null;
|
||||
let loadRequestId = 0;
|
||||
|
||||
@@ -116,10 +117,14 @@ async function loadPdf(index) {
|
||||
const doc = state.documents[index];
|
||||
if (!doc) return;
|
||||
|
||||
// Deduplicate: don't reload the same document
|
||||
if (index === selectedIndex && pdfViewer) {
|
||||
// Deduplicate: don't reload the document that is already shown.
|
||||
// NOTE: must compare against loadedIndex, NOT selectedIndex --
|
||||
// select() updates selectedIndex before calling loadPdf(), so a
|
||||
// selectedIndex comparison is always true and blocks every reload.
|
||||
if (index === loadedIndex && pdfViewer) {
|
||||
return;
|
||||
}
|
||||
loadedIndex = index;
|
||||
|
||||
if (pdfViewer) {
|
||||
pdfViewer.destroy();
|
||||
@@ -164,6 +169,7 @@ async function loadPdf(index) {
|
||||
console.log(`[BizMatch QC] PDF ${reqId} rendering complete`);
|
||||
} catch (error) {
|
||||
if (index !== selectedIndex) return;
|
||||
loadedIndex = -1; // allow retry: clicking the same document again reloads it
|
||||
const message = error instanceof Error ? error.message : String(error);
|
||||
pdfMessage.textContent = `Cannot open PDF: ${message}`;
|
||||
pdfMessage.hidden = false;
|
||||
@@ -281,6 +287,7 @@ async function load() {
|
||||
throw new Error(`State request failed with HTTP ${response.status}.`);
|
||||
}
|
||||
state = await response.json();
|
||||
loadedIndex = -1; // document set changed; index-based dedup is invalid now
|
||||
groups = buildGroups(state.documents);
|
||||
showError(state.loadError || "");
|
||||
renderList();
|
||||
@@ -290,4 +297,4 @@ async function load() {
|
||||
}
|
||||
}
|
||||
|
||||
void load();
|
||||
void load();
|
||||
Reference in New Issue
Block a user