Skip to content

Commit

Permalink
Add polls javascript
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewhope-dev committed Jun 5, 2023
1 parent 08b370f commit fd83feb
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions wwwroot/js/polls.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import * as client from "./client.js";

async function pollExampleAsync() {
let postsDiv = document.getElementById("posts");
let x = document.createElement("div");
// x.classList.add("post-item");
const itemId = 126809;
let data = null;
while (data === null) {
data = await client.getItemAsync(itemId);
}
let t = document.createElement("h3");
let tt = document.createTextNode(data.title);
t.appendChild(tt);
x.appendChild(t);
// console.log(data);
for (const id of data.parts) {
let data = await client.getItemAsync(id);
let h = document.createElement("h5");
let hT = document.createTextNode(data.text);
let s = document.createElement("p");
let sT = document.createTextNode(data.score);
h.appendChild(hT);
s.appendChild(sT);
x.appendChild(h);
x.appendChild(s);
}
postsDiv.appendChild(x);
return data;
}

window.addEventListener("load", async () => {
await pollExampleAsync();
})

0 comments on commit fd83feb

Please sign in to comment.