diff options
author | crupest <crupest@outlook.com> | 2022-11-26 20:47:11 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2022-11-26 20:47:11 +0800 |
commit | e6c4b5249c7055fe323896041044bd7d515490ca (patch) | |
tree | 562780591efc00f223e7603247fb48be7679afc3 /docker/crupest-nginx/sites/www/src/main.js | |
parent | 80bb178ab3234fb7b883c6489ff3c5e2631e208e (diff) | |
download | crupest-e6c4b5249c7055fe323896041044bd7d515490ca.tar.gz crupest-e6c4b5249c7055fe323896041044bd7d515490ca.tar.bz2 crupest-e6c4b5249c7055fe323896041044bd7d515490ca.zip |
Complete crupest-api.
Diffstat (limited to 'docker/crupest-nginx/sites/www/src/main.js')
-rw-r--r-- | docker/crupest-nginx/sites/www/src/main.js | 62 |
1 files changed, 13 insertions, 49 deletions
diff --git a/docker/crupest-nginx/sites/www/src/main.js b/docker/crupest-nginx/sites/www/src/main.js index bbdecab..111b0bd 100644 --- a/docker/crupest-nginx/sites/www/src/main.js +++ b/docker/crupest-nginx/sites/www/src/main.js @@ -1,4 +1,3 @@ -import { Octokit } from "https://cdn.skypack.dev/octokit"; import "./style.css"; const colorStripContainer = document.getElementById("color-strip-container"); @@ -21,63 +20,28 @@ document.addEventListener("DOMContentLoaded", async () => { const todoMessage = document.getElementById("todo-message"); const todoContainer = document.getElementById("todo-container"); - // TODO: we need another way to do this! - const octokit = new Octokit({ - auth: "xxx", - }); + const res = await fetch("/api/todos"); + const body = res.json(); - try { - const res = await octokit.graphql( - ` - { - user(login: "crupest") { - projectV2(number: 2) { - items(last: 100) { - nodes { - __typename - fieldValueByName(name: "Status") - content { - __typename - ... on Issue { - title - closed - } - ... on PullRequest { - title - closed - } - ... on DraftIssue { - title - } - } - } - } - } - } - } - ` + if (res.status !== 200) { + todoMessage.style.color = "red"; + todoMessage.textContent = + "Failed to fetch TODOs. (Maybe due to rate limit. Please try later.)"; + console.log( + `Failed to get GitHub project info. Status: ${res.status}. Body: ${body}` ); - - const items = res.user.projectV2.items.nodes.map((node) => node.content); - - items.forEach((item) => { - if (item.__typename == "DraftIssue") { - item.closed = false; - } - const { title, closed } = item; + } else { + body.forEach((item) => { + const { status, title, color } = item; const li = document.createElement("li"); const span = document.createElement("span"); - span.textContent = closed ? "Done:" : "Todo:"; - span.style.color = closed ? "green" : "blue"; + span.textContent = status; + span.style.color = color; li.appendChild(span); li.append(title); todoContainer.appendChild(li); }); todoMessage.parentElement.removeChild(todoMessage); - } catch (e) { - todoMessage.style.color = "red"; - todoMessage.textContent = "Failed to fetch TODOs."; - console.log("Failed to get GitHub project info.", e); } }); |