From 6e0dc874269b45de8275fe59a868e7eea4bee061 Mon Sep 17 00:00:00 2001
From: JongYun Jeong <95991290+BellYun@users.noreply.github.com>
Date: Thu, 23 May 2024 13:59:24 +0900
Subject: [PATCH 1/5] =?UTF-8?q?feat=20:=20Form=20=EA=B5=AC=ED=98=84?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/App.js | 15 ++++++++++++++-
src/components/Form.js | 25 +++++++++++++++++++++++--
src/components/Item.js | 6 ++++++
3 files changed, 43 insertions(+), 3 deletions(-)
diff --git a/src/App.js b/src/App.js
index ae5ce50..c6d9300 100644
--- a/src/App.js
+++ b/src/App.js
@@ -1,11 +1,19 @@
+import { useState } from 'react';
import Form from './components/Form';
import Item from './components/Item';
function App() {
+ const [todoList, setTodoList] = useState([]);
+
+ const addTodo = newTodo => {
+ const newTodoList = [...todoList, newTodo];
+ setTodoList(newTodoList);
+ };
+
return (
Todo List
-
+
@@ -14,3 +22,8 @@ function App() {
}
export default App;
+
+// TODO: Todo App을 구현합니다.
+// TODO: [] 할 일이 없으면 "할 일 없음"이 화면에 보여집니다.
+// TODO: []
에서 입력한 할 일을
로 보여줍니다.
+// TODO: [] 최근에 추가한 할 일이 위에 보여집니다.
diff --git a/src/components/Form.js b/src/components/Form.js
index cb405e1..fece11f 100644
--- a/src/components/Form.js
+++ b/src/components/Form.js
@@ -1,10 +1,29 @@
import PropTypes from 'prop-types';
+import { useState } from 'react';
function Form({ onAddTodo }) {
+ const [inputValue, setInputValue] = useState('');
+
+ const OnAdd = newTodo => {
+ onAddTodo(newTodo);
+ };
+
+ const handleInputValueChange = e => {
+ setInputValue(e.target.value);
+ };
+
+ const handleClickAddButton = () => {
+ if (inputValue !== '') {
+ OnAdd(inputValue);
+ }
+ };
+
return (
-
- 추가
+
+ handleClickAddButton}>
+ 추가
+
);
}
@@ -18,3 +37,5 @@ Form.propTypes = {
};
export default Form;
+
+// TODO: input에 입력한 값이 없다면 추가 버튼을 눌러도 onAdd 함수가 호출되지 않습니다
diff --git a/src/components/Item.js b/src/components/Item.js
index a4bd48e..cfc12cb 100644
--- a/src/components/Item.js
+++ b/src/components/Item.js
@@ -30,3 +30,9 @@ Item.propTypes = {
};
export default Item;
+
+// TODO: 할 일을 보여줍니다.
+// TODO: 체크 버튼을 누르면 onCompleteTodo 함수가 호출됩니다.
+// TODO: onCompleteTodo 함수는 할 일의 id와 check 상태를 인자로 받습니다.
+// TODO: 삭제 버튼을 누르면 onDeleteTodo 함수가 호출됩니다.
+// TODO: onDeleteTodo 함수는 할 일의 id를 인자로 받습니다.
From 49550cb1366044d91ba6aab3b23c3b7fc9d66d37 Mon Sep 17 00:00:00 2001
From: JongYun Jeong <95991290+BellYun@users.noreply.github.com>
Date: Thu, 23 May 2024 14:00:35 +0900
Subject: [PATCH 2/5] =?UTF-8?q?fix=20:=20Todo=20=EC=B6=94=EA=B0=80=20?=
=?UTF-8?q?=ED=9B=84=20input=EA=B0=92=20''=EC=9C=BC=EB=A1=9C=20=EB=B3=80?=
=?UTF-8?q?=EA=B2=BD?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/components/Form.js | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/src/components/Form.js b/src/components/Form.js
index fece11f..7d8a37d 100644
--- a/src/components/Form.js
+++ b/src/components/Form.js
@@ -6,6 +6,7 @@ function Form({ onAddTodo }) {
const OnAdd = newTodo => {
onAddTodo(newTodo);
+ setInputValue('');
};
const handleInputValueChange = e => {
@@ -37,5 +38,3 @@ Form.propTypes = {
};
export default Form;
-
-// TODO: input에 입력한 값이 없다면 추가 버튼을 눌러도 onAdd 함수가 호출되지 않습니다
From 183d698870d23d802b388cf61ece06fdf51a5a0c Mon Sep 17 00:00:00 2001
From: JongYun Jeong <95991290+BellYun@users.noreply.github.com>
Date: Thu, 23 May 2024 15:10:47 +0900
Subject: [PATCH 3/5] =?UTF-8?q?feat=20:=20Item=20=EA=B5=AC=ED=98=84?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/App.js | 37 +++++++++++++++++++++++++++++++++++--
src/components/Form.js | 2 +-
src/components/Item.js | 16 ++++++++--------
3 files changed, 44 insertions(+), 11 deletions(-)
diff --git a/src/App.js b/src/App.js
index c6d9300..b0d2c54 100644
--- a/src/App.js
+++ b/src/App.js
@@ -1,4 +1,5 @@
import { useState } from 'react';
+import { v4 as uuidv4 } from 'uuid';
import Form from './components/Form';
import Item from './components/Item';
@@ -6,7 +7,28 @@ function App() {
const [todoList, setTodoList] = useState([]);
const addTodo = newTodo => {
- const newTodoList = [...todoList, newTodo];
+ const uuid = uuidv4();
+ const newTodoForm = {
+ id: uuid,
+ todo: newTodo,
+ isCompleted: false,
+ };
+ const newTodoList = [newTodoForm, ...todoList];
+ setTodoList(newTodoList);
+ };
+
+ const deleteTodo = id => {
+ const newTodoList = todoList.filter(todo => {
+ if (todo.id === id) return false;
+ return true;
+ });
+ setTodoList(newTodoList);
+ };
+
+ const completeTodo = (id, isCompleted) => {
+ const newTodoList = todoList.map(todo =>
+ todo.id === id ? { ...todo, isCompleted: !isCompleted } : todo,
+ );
setTodoList(newTodoList);
};
@@ -15,7 +37,18 @@ function App() {
Todo List
-
+ {todoList?.map(todo => {
+ return (
+
+ );
+ })}
);
diff --git a/src/components/Form.js b/src/components/Form.js
index 7d8a37d..ef13f7a 100644
--- a/src/components/Form.js
+++ b/src/components/Form.js
@@ -22,7 +22,7 @@ function Form({ onAddTodo }) {
return (