Skip to content

Commit 9288e6b

Browse files
authored
Merge pull request #44 from Konkuk-KUIT/hamxxn
[3주차] updateTodo 구현
2 parents cbbb680 + b0ababe commit 9288e6b

File tree

9 files changed

+214
-29
lines changed

9 files changed

+214
-29
lines changed

week2/hamxxn/daangn/index.html

+15-25
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
<head>
44
<meta charset="UTF-8" />
55
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6-
<link rel="stylesheet" href="index.css" />
76
<link rel="stylesheet" href="reset.css" />
7+
<link rel="stylesheet" href="index.css" />
8+
89
<title>daangn</title>
910
</head>
1011
<body>
@@ -178,56 +179,45 @@ <h2 class="product-item__name">커피머신</h2>
178179
</div>
179180

180181
<nav class="bottom-bar">
181-
<input type="radio" id="plus" name="nav" hidden checked />
182-
<label for="plus" class="plus__btn">
183-
<img class="bottom-img" alt="plus 버튼" src="./assets/plus.svg" />
184-
</label>
185-
186-
<input type="radio" id="home" name="nav" hidden />
187-
<label for="home" class="bottom-bar__item">
182+
<button class="plus__btn">
183+
<img alt="plus 버튼" src="./assets/plus.svg" />
184+
</button>
185+
<button class="bottom-bar__item">
188186
<img src="./assets/home_2.svg" alt="홈 버튼" class="bottom-bar__icon" />
189187
<span class="bottom-bar__text"></span>
190-
</label>
191-
192-
<input type="radio" id="neighborhood" name="nav" hidden />
193-
<label for="neighborhood" class="bottom-bar__item">
188+
</button>
189+
<button class="bottom-bar__item">
194190
<img
195191
src="./assets/article.svg"
196192
alt="동네 생활 버튼"
197193
class="bottom-bar__icon"
198194
/>
199195
<span class="bottom-bar__text">동네생활</span>
200-
</label>
201-
202-
<input type="radio" id="nearby" name="nav" hidden />
203-
<label for="nearby" class="bottom-bar__item">
196+
</button>
197+
<button class="bottom-bar__item">
204198
<img
205199
src="./assets/place-marker.svg"
206200
alt="내 근처 버튼"
207201
class="bottom-bar__icon"
208202
/>
209203
<span class="bottom-bar__text">내 근처</span>
210-
</label>
211-
212-
<input type="radio" id="chat" name="nav" hidden />
213-
<label for="chat" class="bottom-bar__item">
204+
</button>
205+
<button class="bottom-bar__item">
214206
<img
215207
src="./assets/chat-message_two.svg"
216208
alt="채팅 버튼"
217209
class="bottom-bar__icon"
218210
/>
219211
<span class="bottom-bar__text">채팅</span>
220-
</label>
221-
222-
<input type="radio" id="my" name="nav" hidden />
223-
<label for="my" class="bottom-bar__item">
212+
</button>
213+
<button class="bottom-bar__item">
224214
<img
225215
src="./assets/user.svg"
226216
alt="나의 당근 버튼"
227217
class="bottom-bar__icon"
228218
/>
229219
<span class="bottom-bar__text">나의 당근</span>
230-
</label>
220+
</button>
231221
</nav>
232222
</body>
233223
</html>

week2/hamxxn/daangn_page2/index.css

+6-1
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ button {
247247
.nav__menu::-webkit-scrollbar,
248248
.post-item__imgs::-webkit-scrollbar,
249249
.post-list::-webkit-scrollbar {
250-
height: 1px;
250+
height: 0px;
251251
}
252252
.post-item .post-item__location {
253253
display: flex;
@@ -291,6 +291,7 @@ button {
291291
flex-direction: column;
292292
justify-content: center;
293293
align-items: center;
294+
gap: 4px;
294295
}
295296
.plus__btn {
296297
position: fixed;
@@ -304,3 +305,7 @@ button {
304305
align-items: center;
305306
border-radius: 100%;
306307
}
308+
309+
input[type="radio"]:checked + label > img {
310+
background-color: #ff7e36;
311+
}

week2/hamxxn/daangn_page2/index.html

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
<head>
44
<meta charset="UTF-8" />
55
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6-
<link rel="stylesheet" href="index.css" />
76
<link rel="stylesheet" href="reset.css" />
7+
<link rel="stylesheet" href="index.css" />
8+
89
<title>daangn</title>
910
</head>
1011
<body>

week3/hamxxn/todo/app.js

+99
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
const todoListEl = document.getElementById("todoList");
2+
const todoInputEl = document.getElementById("todoInput");
3+
4+
const API_URL = "http://localhost:3000/todos";
5+
6+
fetch(API_URL)
7+
.then((response) => response.json())
8+
.then((data) => renderTodo(data))
9+
.catch((error) => console.log("error: " + error));
10+
11+
const renderTodo = (newTodos) => {
12+
todoListEl.innerHTML = "";
13+
newTodos.forEach((todo) => {
14+
const listEl = document.createElement("li");
15+
listEl.textContent = todo.title;
16+
listEl.id = `todo-${todo.id}`;
17+
18+
const deleteEl = document.createElement("span");
19+
deleteEl.textContent = "🗑️";
20+
deleteEl.onclick = () => deleteTodo(todo.id);
21+
22+
const udpateEl = document.createElement("span");
23+
udpateEl.textContent = "✏️";
24+
udpateEl.onclick = () => updateTodo(todo.id, todo.title);
25+
26+
listEl.append(deleteEl);
27+
listEl.append(udpateEl);
28+
todoListEl.append(listEl);
29+
});
30+
};
31+
32+
const addTodo = () => {
33+
const title = todoInputEl.value;
34+
const date = new Date();
35+
const createdAt = date.toDateString();
36+
37+
if (!title) return;
38+
39+
const newTodo = {
40+
title,
41+
createdAt,
42+
completed: false,
43+
};
44+
45+
fetch(API_URL, {
46+
method: "POST",
47+
headers: {
48+
"Content-Type": "application/json",
49+
},
50+
body: JSON.stringify({ ...newTodo, completed: false }),
51+
})
52+
.then((response) => response.json())
53+
.then(() => {
54+
todoInputEl.value = "";
55+
return fetch(API_URL);
56+
})
57+
.then((response) => response.json())
58+
.then((data) => renderTodo(data));
59+
};
60+
const deleteTodo = (todoId) => {
61+
console.log(todoId);
62+
fetch(API_URL + "/" + todoId, {
63+
method: "DELETE",
64+
})
65+
.then(() => fetch(API_URL))
66+
.then((response) => response.json())
67+
.then((data) => renderTodo(data));
68+
};
69+
//연필 이모지 누르면 input으로 바뀌고 enter 누르면 바뀜
70+
const updateTodo = (todoId, originalTitle) => {
71+
const todoItem = document.querySelector(`#todo-${todoId}`);
72+
73+
const updateInput = document.createElement("input");
74+
updateInput.type = "text";
75+
updateInput.value = originalTitle;
76+
todoItem.innerHTML = "";
77+
78+
todoItem.append(updateInput);
79+
updateInput.onkeydown = () => {
80+
console.log("inner");
81+
if (event.key == "Enter") {
82+
fetch(API_URL + "/" + todoId, {
83+
method: "PUT",
84+
headers: {
85+
"Content-Type": "application/json",
86+
},
87+
body: JSON.stringify({
88+
title: updateInput.value,
89+
}),
90+
})
91+
.then(() => {
92+
todoItem.innerHTML = "";
93+
return fetch(API_URL);
94+
})
95+
.then((response) => response.json())
96+
.then((data) => renderTodo(data));
97+
}
98+
};
99+
};

week3/hamxxn/todo/db.json

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"todos": []
3+
}

week3/hamxxn/todo/index.css

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
* {
2+
box-sizing: border-box;
3+
margin: 0;
4+
padding: 0;
5+
}
6+
body {
7+
background-color: #f5f5f5;
8+
font-family: "Arial", sans-serif;
9+
}
10+
.app {
11+
width: 400px;
12+
margin: 30px auto;
13+
background-color: #fff;
14+
padding: 20px;
15+
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
16+
}
17+
.header {
18+
font-size: 1.5em;
19+
margin-bottom: 20px;
20+
text-align: center;
21+
}
22+
.inputContainer {
23+
display: flex;
24+
}
25+
#todoInput {
26+
flex: 1;
27+
padding: 10px;
28+
font-size: 1em;
29+
border: 1px solid #ddd;
30+
}
31+
button {
32+
background-color: #28a745;
33+
color: #fff;
34+
padding: 10px;
35+
font-size: 1em;
36+
cursor: pointer;
37+
}
38+
button:hover {
39+
background-color: #218838;
40+
}
41+
ul {
42+
list-style-type: none;
43+
}
44+
li {
45+
padding: 10px;
46+
border-bottom: 1px solid #ddd;
47+
display: flex;
48+
justify-content: space-between;
49+
align-items: center;
50+
}
51+
li:last-child {
52+
border-bottom: none;
53+
}
54+
.deleteBtn {
55+
cursor: pointer;
56+
color: #ff0000;
57+
}
58+
.deleteBtn:hover {
59+
text-decoration: underline;
60+
}

week3/hamxxn/todo/index.html

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<title>Todo App</title>
6+
<link rel="stylesheet" href="index.css" />
7+
</head>
8+
<body>
9+
<div class="app">
10+
<div class="header">My Todos</div>
11+
<div class="inputContainer">
12+
<input id="todoInput" placeholder="What needs to be done?" />
13+
<button onclick="addTodo()">Add</button>
14+
</div>
15+
<ul id="todoList"></ul>
16+
</div>
17+
<script src="app.js"></script>
18+
</body>
19+
</html>

week3/jinho1011/es6/index.js

+10
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,14 @@ const arr2 = arr.reduce((prevValue, currValue) => {
55
return prevValue + currValue;
66
});
77

8+
const arr3 = arr.map((value, idx) => {
9+
console.log(value, idx);
10+
return value;
11+
});
12+
const arr4 = arr
13+
.filter((value) => {
14+
return value > 0;
15+
})
16+
.map((value, index) => value + 10);
17+
818
console.log(arr2);

week3/jinho1011/todo/db.json

-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
{
22
"todos": [
33
{
4-
"id": 1695583514152,
54
"title": "1asd",
65
"createdAt": "Mon Sep 25 2023",
76
"completed": false
87
},
98
{
10-
"id": 1695583514985,
119
"title": "2asd",
1210
"createdAt": "Mon Sep 25 2023",
1311
"completed": false

0 commit comments

Comments
 (0)