aboutsummaryrefslogtreecommitdiff
path: root/docker/crupest-nginx/sites/www/src/main.js
blob: 04d7b6b3cf8a5862f53a2ab32f626551d349b90f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import "./style.css";

const happy = "happy";
const angry = "angry";

function emotionOpposite(emotion) {
  if (emotion === happy) {
    return angry;
  } else if (emotion === angry) {
    return happy;
  }
}

function emotionElement(emotion) {
  return document.querySelector(`.slogan.${emotion}`);
}

function emotionElementHeight(emotion) {
  return emotionElement(emotion).clientHeight;
}

function setBodyPaddingForEmotion(emotion) {
  document.body.style.paddingTop = `${emotionElementHeight(emotion)}px`;
}

setBodyPaddingForEmotion(happy);

/** @type {HTMLDivElement} */
const sloganContainer = document.querySelector(".slogan-container")

for (const emotion of [happy, angry]) {
  emotionElement(emotion).addEventListener("click", () => {
    const opposite = emotionOpposite(emotion);
    sloganContainer.dataset.sloganEmotion = opposite;
    setBodyPaddingForEmotion(opposite);
  });
}


document.addEventListener("DOMContentLoaded", async () => {
  console.log("Try to fetch GitHub project(number: 2) of crupest.");

  const todoMessage = document.getElementById("todo-message");
  const todoContainer = document.getElementById("todo-container");

  const res = await fetch("/api/todos");
  const body = await res.json();

  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}`
    );
  } else {
    body.forEach((item) => {
      const { status, title, color } = item;
      const li = document.createElement("li");
      const statusSpan = document.createElement("span");
      const titleSpan = document.createElement("span");
      statusSpan.textContent = status;
      statusSpan.style.color = color;
      titleSpan.textContent = title;
      li.appendChild(statusSpan);
      li.append(" : ");
      li.append(titleSpan);
      todoContainer.appendChild(li);
    });

    todoMessage.parentElement.removeChild(todoMessage);
  }
});