-
Notifications
You must be signed in to change notification settings - Fork 2
/
addpost-it(concept).html
126 lines (111 loc) · 3.88 KB
/
addpost-it(concept).html
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>포스트잇 추가 개념</title>
<link rel="stylesheet" href="./css/add-post.css" />
<link rel="stylesheet" href="./css/common.css" />
</head>
<body>
<div class="rectangle">
<div class="title">개념</div>
<div class="subtitle">중요도</div>
<button class="custom-button" id="button1" value="1">
<img src="images/Group 15.svg" alt="Button 1" />
</button>
<button class="custom-button" id="button2" value="2">
<img src="images/Group 16.svg" alt="Button 2" />
</button>
<button class="custom-button" id="button3" value="3">
<img src="images/Group 17.svg" alt="Button 3" />
</button>
<div class="custom-rectangle">
<textarea
id="description"
placeholder="개념을 입력해주세요(300글자 이내)"></textarea>
</div>
<button type="button" id="submit-button" onclick="createPostit()">
포스트잇 생성
</button>
</div>
<div class="widget">
<a class="image-button" href="home.html"
><img src="images/home.png" alt="이미지 1"
/></a>
<a class="image-button" href="category(concept).html"
><img src="images/개념.png" alt="이미지 2"
/></a>
<a class="image-button" href="category(quiz).html"
><img src="images/퀴즈.png" alt="이미지 3"
/></a>
<a class="image-button" href="category(wronganswer).html"
><img src="images/오답.png" alt="이미지 4"
/></a>
</div>
<script>
async function getToken() {
try {
const response = await fetch("http://localhost:3000/token");
if (!response.ok) {
throw new Error("Network response was not ok");
}
const data = await response.json();
return data.token;
} catch (error) {
console.error("Error fetching token:", error);
throw error;
}
}
async function postData(importance, description) {
const apiUrl = "http://localhost:3000/concept";
const token = await getToken();
const data = {
token: token,
importance: importance,
description: description,
};
try {
const response = await fetch(apiUrl, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(data),
});
if (!response.ok) {
throw new Error("Network response was not ok");
}
const responseData = await response.json();
console.log("Data:", responseData);
} catch (error) {
console.error("Error:", error);
}
}
function createPostit() {
const selectedButton = document.querySelector(
".custom-button.selected"
);
const description = document.getElementById("description").value;
if (!selectedButton || !description) {
console.error("Please select a button and provide a description.");
return;
}
postData(selectedButton.value, description);
}
function addButtonClickHandler(buttonId) {
const button = document.getElementById(buttonId);
button.addEventListener("click", () => {
const buttons = document.querySelectorAll(".custom-button");
buttons.forEach((btn) => btn.classList.remove("selected"));
button.classList.add("selected");
});
}
// 각 버튼에 이벤트 핸들러 추가
addButtonClickHandler("button1");
addButtonClickHandler("button2");
addButtonClickHandler("button3");
</script>
</body>
</html>