workin on drawing

This commit is contained in:
Bel LaPointe
2024-02-20 14:26:52 -07:00
parent 2520e8156b
commit f5bd9f27ce
2 changed files with 41 additions and 5 deletions

View File

@@ -23,8 +23,10 @@
function pollState() {
http("GET", "/api/v1/questions", (body) => {
if (!body)
return;
g_questions = JSON.parse(body);
console.log("polled state:", body);
console.log("TODO polled state:", body);
pollLiveAnswer();
pollLiveQuestion();
});
@@ -35,12 +37,28 @@
if (live_questions) {
g_live_question = live_questions[0];
}
if (g_live_question) {
document.getElementById("question-text").innerHTML = g_live_question.Text;
let options = "";
for (let i of g_live_question.Options)
options += `<li>${i}</li>`;
document.getElementById("question-options").innerHTML = options;
}
}
function pollLiveAnswer() {
if (!g_live_question || !g_live_question.Closed) {
document.getElementById("answers").hidden = true;
return;
}
document.getElementById("answers").hidden = false;
http("GET", `/api/v1/questions/${g_live_question.ID}/answers`, (body) => {
let answers = JSON.parse(body);
let result = "";
for (let i of answers)
result += `<br>${i}`;
document.getElementById("answers").innerHTML = result;
});
}
function http(method, remote, callback, body) {
@@ -58,7 +76,11 @@
}
pollState();
setInterval(() => { pollState(); }, 1000);
setInterval(() => {
try {
pollState();
} catch {}
}, 1000);
</script>
</footer>
</html>