-
Notifications
You must be signed in to change notification settings - Fork 10
[1주차] 정성훈 과제 제출합니다. #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| <!DOCTYPE html> | ||
| <html lang="ko"> | ||
| <head> | ||
| <meta charset="UTF-8"> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
| <title>to do list</title> | ||
| <link rel="stylesheet" href="style.css"> | ||
| </head> | ||
| <body> | ||
| <header>투두리스트</header> | ||
| <main id="main_contents"> | ||
| <section> | ||
| <div id="date_container"> | ||
| <button id="date_prev"><</button> | ||
| | ||
| <span id="date_span">날짜</span> | ||
| | ||
| <button id="date_next">></button> | ||
| </div> | ||
| </section> | ||
| <section> | ||
| <div id="input_container"> | ||
| <input id="todo_input" type="text" placeholder="할 일을 적어주세요."/> | ||
| <button id="add_button">등록</button> | ||
| </div> | ||
| </section> | ||
| <section> | ||
| <div id="list_container"> | ||
| <ul id="todo_list"> | ||
| </ul> | ||
| </div> | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 해당 날짜에 todo가 없으면 빈 상자 대신 '할 일을 추가하세요' 같은 UI 요소를 추가하면 더 좋을 거 같아요 |
||
| </main> | ||
| </section> | ||
| <script src="script.js"></script> | ||
| </body> | ||
| </html> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| const todoInput = document.getElementById('todo_input'); | ||
| const addButton = document.getElementById('add_button'); | ||
| const todoList = document.getElementById('todo_list'); | ||
| const dateSpan = document.getElementById('date_span'); | ||
| const prevButton = document.getElementById('date_prev'); | ||
| const nextButton = document.getElementById('date_next'); | ||
|
|
||
| let todos = JSON.parse(localStorage.getItem('todos')) || {}; | ||
|
|
||
| // 오늘 날짜 | ||
| let currentDate = new Date(); | ||
|
|
||
| // 날짜 포멧 변환 | ||
| function formatDate(date) { | ||
| return date.toISOString().split('T')[0]; | ||
| } | ||
|
|
||
| // 날짜 갱신 | ||
| function updateDate() { | ||
| dateSpan.textContent = formatDate(currentDate); | ||
| } | ||
|
|
||
| // 투두 불러오기 | ||
| function renderTodos() { | ||
| const selectDate = formatDate(currentDate); | ||
| const todayTodos = todos[selectDate] || []; | ||
|
|
||
| todoList.innerHTML = ''; | ||
|
|
||
| todayTodos.forEach((todo, index) => { | ||
| const li = document.createElement('li'); | ||
| li.textContent = todo; | ||
|
|
||
| // 삭제 버튼 추가 | ||
| const deleteButton = document.createElement('button'); | ||
| deleteButton.textContent = '삭제'; | ||
| deleteButton.addEventListener('click', () => { | ||
| todayTodos.splice(index, 1); | ||
| todos[selectDate] = todayTodos; | ||
| localStorage.setItem('todos', JSON.stringify(todos)); | ||
| renderTodos(); | ||
| }); | ||
| li.appendChild(deleteButton); | ||
| todoList.appendChild(li); | ||
| }); | ||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 리팩토링 하실 때 |
||
|
|
||
| // 투두 추가 | ||
| addButton.addEventListener('click', () => { | ||
| const text = todoInput.value.trim(); | ||
| if (text === '') return; | ||
|
|
||
| const date = formatDate(currentDate); | ||
| if (!todos[date]) { | ||
| todos[date] = []; | ||
| } | ||
| todos[date].push(text); | ||
|
|
||
| localStorage.setItem('todos', JSON.stringify(todos)); | ||
| todoInput.value = ''; | ||
| renderTodos(); | ||
| }); | ||
|
|
||
| // 전날 버튼 클릭 | ||
| prevButton.addEventListener('click', () => { | ||
| currentDate.setDate(currentDate.getDate() - 1); | ||
| updateDate(); | ||
| renderTodos(); | ||
| }); | ||
|
|
||
| // 다음날 버튼 클릭 | ||
| nextButton.addEventListener('click', () => { | ||
| currentDate.setDate(currentDate.getDate() + 1); | ||
| updateDate(); | ||
| renderTodos(); | ||
| }); | ||
|
Comment on lines
+49
to
+76
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 버튼마다 addEventListener로 세분화되어 겹치는 코드들이 있습니다 |
||
|
|
||
| // 초기화 | ||
| updateDate(); | ||
| renderTodos(); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| @font-face { | ||
| font-family: 'Pretendard'; | ||
| src: url('https://cdn.jsdelivr.net/gh/Project-Noonnu/noonfonts_2107@1.1/Pretendard-Thin.woff') format('woff'); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. pretendard 웹 폰트 적용하신 거 좋은 거 같아요. 다만 woff2 format이라는 개선 버전이 출시되었으니 해당 형식 사용하시면 더 좋을 거 같아요. 더불어서 지금은 이렇게 font-weight 100만 사용하셨는데, 추후 pretendard variable 파일 다운받아서 사용하시면 import 한 번으로 100-900 weight 다 사용하실 수 있답니다 |
||
| font-weight: 100; | ||
| font-display: swap; | ||
| } | ||
| body { | ||
| font-family: 'Pretendard'; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이렇게 Pretendard 적용하신 건 좋은 거 같아요. 다만 웹 페이지 랜더링이 느리거나 오류가 날 경우를 대비하여 |
||
| display: flex; | ||
| flex-direction: column; | ||
| align-items: center; | ||
| justify-content: center; | ||
| } | ||
| #main_contents{ | ||
| display: flex; | ||
| flex-direction: column; | ||
| justify-content: center; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 가독성을 위하여 tab 해주시면 좋을 거 같아요 |
||
| align-items: center; | ||
| } | ||
| #list_container{ | ||
| border: 1px solid black; | ||
| padding-right: 30px; | ||
| margin-top: 30px; | ||
| } | ||
| #date_container{ | ||
| border: 1px solid black; | ||
| padding: 15px; | ||
| margin-top: 15px; | ||
| margin-bottom: 15px; | ||
| } | ||
| #input_container{ | ||
| margin-top: 15px; | ||
| } | ||
| #todo_input{ | ||
| padding: 5px; | ||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. class 대신 id 기반으로 코딩하신 거 좋은 거 같아요 |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이렇게 nbsp 사용하시는 것도 좋지만, 추후 과제에서는 display flex 같은 요소를 사용하시면 좀 더 안정적인 코드가 될 거 같아요