dfgdf
This commit is contained in:
27
web/app.js
27
web/app.js
@@ -2,6 +2,7 @@ let state;
|
||||
let groups = [];
|
||||
let selectedIndex = -1;
|
||||
let pdfViewer = null;
|
||||
let loadRequestId = 0;
|
||||
|
||||
const people = document.querySelector("#people");
|
||||
const fields = document.querySelector("#fields");
|
||||
@@ -112,6 +113,14 @@ function renderList() {
|
||||
}
|
||||
|
||||
async function loadPdf(index) {
|
||||
const doc = state.documents[index];
|
||||
if (!doc) return;
|
||||
|
||||
// Deduplicate: don't reload the same document
|
||||
if (index === selectedIndex && pdfViewer) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (pdfViewer) {
|
||||
pdfViewer.destroy();
|
||||
}
|
||||
@@ -120,12 +129,18 @@ async function loadPdf(index) {
|
||||
pdfMessage.hidden = false;
|
||||
pdfMessage.textContent = "Loading PDF\u2026";
|
||||
|
||||
const reqId = "pdf-" + (++loadRequestId);
|
||||
console.log(
|
||||
`[BizMatch QC] PDF ${reqId} selection: ${doc._letter}/${doc.file_name}`,
|
||||
);
|
||||
console.log(`[BizMatch QC] PDF ${reqId} prepare requested`);
|
||||
|
||||
const startTime = performance.now();
|
||||
try {
|
||||
const response = await fetch("/api/pdf/prepare", {
|
||||
method: "POST",
|
||||
headers: { "content-type": "application/json" },
|
||||
body: JSON.stringify({ index }),
|
||||
body: JSON.stringify({ index, requestId: reqId }),
|
||||
});
|
||||
if (!response.ok) {
|
||||
const body = await response.json().catch(() => ({}));
|
||||
@@ -134,13 +149,21 @@ async function loadPdf(index) {
|
||||
const data = await response.json();
|
||||
const prepareMs = Math.round(performance.now() - startTime);
|
||||
console.log(
|
||||
`[BizMatch QC] PDF prepare: ${prepareMs}ms, disk cache ${data.cacheStatus}`,
|
||||
`[BizMatch QC] PDF ${reqId} prepare: ${prepareMs}ms, disk cache ${data.cacheStatus}`,
|
||||
);
|
||||
|
||||
if (index !== selectedIndex) {
|
||||
// A newer selection happened while preparing, don't show stale result
|
||||
return;
|
||||
}
|
||||
|
||||
viewer.classList.add("loaded");
|
||||
pdfMessage.hidden = true;
|
||||
console.log(`[BizMatch QC] PDF ${reqId} viewer load started`);
|
||||
await pdfViewer.load(data.url, data.size);
|
||||
console.log(`[BizMatch QC] PDF ${reqId} rendering complete`);
|
||||
} catch (error) {
|
||||
if (index !== selectedIndex) return;
|
||||
const message = error instanceof Error ? error.message : String(error);
|
||||
pdfMessage.textContent = `Cannot open PDF: ${message}`;
|
||||
pdfMessage.hidden = false;
|
||||
|
||||
Reference in New Issue
Block a user