dfgdfg
This commit is contained in:
41
web/app.js
41
web/app.js
@@ -1,19 +1,20 @@
|
||||
let state;
|
||||
let groups = [];
|
||||
let selectedIndex = -1;
|
||||
let pdfViewer = null;
|
||||
let currentPdfKey = null;
|
||||
let loadRequestId = 0;
|
||||
|
||||
const people = document.querySelector("#people");
|
||||
const fields = document.querySelector("#fields");
|
||||
const viewer = document.querySelector(".viewer");
|
||||
const pdfContainer = document.querySelector("#pdfViewer");
|
||||
const viewerSection = document.querySelector(".viewer");
|
||||
const pdfFrame = document.querySelector("#pdfFrame");
|
||||
const pdfMessage = document.querySelector("#pdfMessage");
|
||||
const status = document.querySelector("#status");
|
||||
const search = document.querySelector("#search");
|
||||
const errorBanner = document.querySelector("#errorBanner");
|
||||
|
||||
const pdfViewer = new NativePdfViewer(pdfFrame, viewerSection);
|
||||
|
||||
const fieldDefs = [
|
||||
["Name / Company", "name_company"],
|
||||
["Prospective Buyer", "prospective_buyer"],
|
||||
@@ -158,20 +159,11 @@ async function openDocument(index, { force = false } = {}) {
|
||||
}
|
||||
`;
|
||||
|
||||
// Load PDF
|
||||
if (pdfViewer) {
|
||||
pdfViewer.destroy();
|
||||
}
|
||||
pdfViewer = new PdfViewer(pdfContainer);
|
||||
viewer.classList.remove("loaded");
|
||||
pdfMessage.hidden = false;
|
||||
pdfMessage.textContent = "Loading PDF\u2026";
|
||||
|
||||
const reqId = "pdf-" + (++loadRequestId);
|
||||
console.log(
|
||||
`[BizMatch QC] Document selected: ${key}`,
|
||||
);
|
||||
console.log(`[BizMatch QC] PDF prepare starting: ${reqId}`);
|
||||
console.log(`[BizMatch QC] Native PDF prepare: ${reqId} (${key})`);
|
||||
|
||||
const startTime = performance.now();
|
||||
try {
|
||||
@@ -187,19 +179,17 @@ async function openDocument(index, { force = false } = {}) {
|
||||
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] Native PDF prepare: ${prepareMs}ms, cache ${data.cacheStatus}`,
|
||||
);
|
||||
console.log(`[BizMatch QC] PDF viewer URL received: ${reqId}`);
|
||||
|
||||
if (key !== currentPdfKey) {
|
||||
// A newer document was selected while preparing
|
||||
return;
|
||||
}
|
||||
|
||||
viewer.classList.add("loaded");
|
||||
await pdfViewer.load(data.url, data.size, key);
|
||||
pdfMessage.hidden = true;
|
||||
await pdfViewer.load(data.url, data.size);
|
||||
console.log(`[BizMatch QC] PDF ${reqId} rendering complete`);
|
||||
console.log(`[BizMatch QC] Native PDF loaded: ${reqId}`);
|
||||
} catch (error) {
|
||||
if (key !== currentPdfKey) return;
|
||||
const message = error instanceof Error ? error.message : String(error);
|
||||
@@ -208,18 +198,9 @@ async function openDocument(index, { force = false } = {}) {
|
||||
}
|
||||
}
|
||||
|
||||
function select(index) {
|
||||
openDocument(index);
|
||||
}
|
||||
|
||||
// Exposed for future retry from viewer; use openDocument(_, {force:true})
|
||||
function _selectForced(index) {
|
||||
openDocument(index, { force: true });
|
||||
}
|
||||
|
||||
people.addEventListener("click", (event) => {
|
||||
const button = event.target.closest("[data-index]");
|
||||
if (button) select(Number(button.dataset.index));
|
||||
if (button) openDocument(Number(button.dataset.index));
|
||||
});
|
||||
|
||||
search.addEventListener("input", renderList);
|
||||
@@ -229,7 +210,7 @@ document.addEventListener("keydown", (event) => {
|
||||
if (event.key === "ArrowDown" || event.key === "ArrowUp") {
|
||||
event.preventDefault();
|
||||
const delta = event.key === "ArrowDown" ? 1 : -1;
|
||||
select(
|
||||
openDocument(
|
||||
Math.max(
|
||||
0,
|
||||
Math.min(
|
||||
@@ -295,7 +276,7 @@ async function load() {
|
||||
groups = buildGroups(state.documents);
|
||||
showError(state.loadError || "");
|
||||
renderList();
|
||||
if (state.documents.length) select(0);
|
||||
if (state.documents.length) openDocument(0);
|
||||
} catch (error) {
|
||||
showError(error instanceof Error ? error.message : String(error));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user