28 lines
990 B
JavaScript
28 lines
990 B
JavaScript
import { $, h, api, pollId, hashKey, resultsView } from "./common.js";
|
|
|
|
const pid = pollId();
|
|
// the key stays in the address bar so the link can be passed on as is
|
|
const key = hashKey();
|
|
|
|
async function load() {
|
|
let data;
|
|
try { data = await api("GET", `/api/r/${pid}`, undefined, key); }
|
|
catch {
|
|
$("#denied").hidden = false;
|
|
$("#list").replaceChildren();
|
|
return;
|
|
}
|
|
$("#denied").hidden = true;
|
|
$("#title").textContent = data.title;
|
|
document.title = `Résultats · ${data.title}`;
|
|
const qs = data.questions.sort((a, b) => a.id - b.id);
|
|
$("#list").replaceChildren(...(qs.length
|
|
? qs.map((q) => h("article", { class: "q" }, h("div", { class: "q-text" }, q.text), resultsView(q)))
|
|
: [h("p", { class: "muted" }, "Aucun résultat pour l'instant.")]));
|
|
}
|
|
|
|
load();
|
|
// questions get added as the meeting goes on
|
|
setInterval(() => { if (!document.hidden) load(); }, 15000);
|
|
document.addEventListener("visibilitychange", () => { if (!document.hidden) load(); });
|