42 lines
1.4 KiB
JavaScript
42 lines
1.4 KiB
JavaScript
// bookmark/bookmark/static/app.js
|
|
const statusEl = document.getElementById("status");
|
|
const hintEl = document.getElementById("hint");
|
|
const previewEl = document.getElementById("preview");
|
|
const triggerButton = document.getElementById("trigger-button");
|
|
|
|
const STATE_COPY = {
|
|
waiting_front: { status: "Waiting for book...", hint: "Center the front cover in the guide box." },
|
|
waiting_back: { status: "Front captured — flip it over", hint: "Center the back cover in the guide box." },
|
|
book_complete: { status: "Book complete!", hint: "Tap Next Book to continue." },
|
|
};
|
|
|
|
async function refreshStatus() {
|
|
const response = await fetch("/api/session-state");
|
|
const body = await response.json();
|
|
const copy = STATE_COPY[body.state] || { status: body.state, hint: "" };
|
|
statusEl.textContent = copy.status;
|
|
hintEl.textContent = copy.hint;
|
|
triggerButton.textContent = body.state === "book_complete" ? "Next Book" : "Capture";
|
|
}
|
|
|
|
function refreshPreview() {
|
|
previewEl.src = `/api/preview.jpg?ts=${Date.now()}`;
|
|
}
|
|
|
|
async function observe() {
|
|
await fetch("/api/observe", { method: "POST" });
|
|
await refreshStatus();
|
|
}
|
|
|
|
triggerButton.addEventListener("click", async () => {
|
|
if (statusEl.textContent === "Book complete!") {
|
|
await fetch("/api/next-book", { method: "POST" });
|
|
} else {
|
|
await fetch("/api/manual-trigger", { method: "POST" });
|
|
}
|
|
await refreshStatus();
|
|
});
|
|
|
|
setInterval(observe, 500);
|
|
setInterval(refreshPreview, 500);
|
|
refreshStatus();
|