Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions index.html
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>
&nbsp;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이렇게 nbsp 사용하시는 것도 좋지만, 추후 과제에서는 display flex 같은 요소를 사용하시면 좀 더 안정적인 코드가 될 거 같아요

<span id="date_span">날짜</span>
&nbsp;
<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>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

해당 날짜에 todo가 없으면 빈 상자 대신 '할 일을 추가하세요' 같은 UI 요소를 추가하면 더 좋을 거 같아요

</main>
</section>
<script src="script.js"></script>
</body>
</html>
80 changes: 80 additions & 0 deletions script.js
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);
});
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

리팩토링 하실 때 display: flex; justify-content: between; 사용하시면 좀 더 심미안적으로 좋은 UI가 될 거 같아요


// 투두 추가
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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

버튼마다 addEventListener로 세분화되어 겹치는 코드들이 있습니다
하나의 addEventListener로 합치면 중복 코드들이 다소 줄어들 것 같습니다


// 초기화
updateDate();
renderTodos();
36 changes: 36 additions & 0 deletions style.css
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');
Copy link
Member

Choose a reason for hiding this comment

The 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';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이렇게 Pretendard 적용하신 건 좋은 거 같아요. 다만 웹 페이지 랜더링이 느리거나 오류가 날 경우를 대비하여 font-family: 'Pretendard', sans-serif; 이런 식으로 예비 시스템 폰트도 추가해놓으시면 더 좋은 코드가 될 것 같아요

display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
#main_contents{
display: flex;
flex-direction: column;
justify-content: center;
Copy link
Member

Choose a reason for hiding this comment

The 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;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

class 대신 id 기반으로 코딩하신 거 좋은 거 같아요