Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
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
14 changes: 14 additions & 0 deletions App.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
.App {
width: 500px;
margin:0 auto;
display: flex;
flex-direction: column;
gap: 20px;
}

.checkbtn{
width: 120px;
height: 40px;
border-radius: 5px;
border: 10px;
}
58 changes: 58 additions & 0 deletions App.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import React, {useCallback, useState} from "react"
import "./App.css"
import Header from "./src/component/Header"
import List from "./src/component/List"
import Todomaker from "./src/component/Todomaker"
import ReactDOM from "react-dom/client";
function App(){



const [TodoList, setTodoList] = useState([])
const [checkTodoList, setCheckTodoList] = useState([])
const [showChecked, setShowChecked] = useState(false)

const onRemove = (id) => {
setTodoList(TodoList.filter((todo) => todo.id !== id))
setCheckTodoList(checkTodoList.filter((todo) => todo.id !== id));
}

const checkPush = (id, content) => {
const newcheck = {
id : id,
isDone : true,
content : content

}
setCheckTodoList([...checkTodoList, newcheck])
}
const toggleCheckedList = () => {
setShowChecked(!showChecked); // 버튼 클릭 이벤트 핸들링 함수
};

const addNewTodo = (content)=> {
const newTodo = {
id:TodoList.length,
isDone : false,
content : content
};
setTodoList([...TodoList, newTodo])
}
return (
<div className="App">
<Header/>
<Todomaker addNewTodo = {addNewTodo}/>
<button className="checkbtn" onClick={toggleCheckedList}>
{showChecked ? "모든 항목 보기" : "완료한 항목 보기"}
</button>
<List TodoList = {showChecked ? checkTodoList : TodoList} onRemove={onRemove} checkPush = {checkPush}/>
</div>
)




}
const root = ReactDOM.createRoot(document.getElementById("App"));
root.render(<App />);
export default App;
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,17 @@
# react-todo-list-precourse
# react-todo-list-precourse

기본 기능 구현 목록
1. 기본적인 ui, component 구성 - 완료
2. 값 가져오기 -> 엔터로 값을 가져오도록 - 완료
3. 가져온 값을 나타내기 - 완료
4. 수정하기
5. 삭제하기 - 완료
6. 완료 체크박스 - 체크박스만 구현
7. 완료 체크박스 누른것들만 보이기 구현

미구현 요소
1. 날짜,날씨
2. 완료 못한것들만 보이기
3. 완료 체크박스 누르면 밑줄 표시
4. 깔끔한 css

4 changes: 2 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<title></title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.js"></script>
<div id="App"></div>
<script type="module" src="/App.jsx"></script>
</body>
</html>
7 changes: 7 additions & 0 deletions src/component/Header.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const Header = () => {
return <div>
<h3>ToDo-List 🤯</h3>
</div>
};

export default Header;
14 changes: 14 additions & 0 deletions src/component/List.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
.List{
display: flex;
flex-direction: column;
width: 100%;
gap: 20px;
padding-bottom: 20px;
}
.List-wrapper{
display: flex;
flex-direction: column;
gap: 10px;


}
18 changes: 18 additions & 0 deletions src/component/List.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import React from "react";
import TodoThing from "./TodoThing";
import "./List.css"

const List = ({TodoList, onRemove, checkPush}) => {
return <div className="List">
<h3>List</h3>
<div className="List-wrapper">
{TodoList.map((todo) => (
<TodoThing key={todo.id} todo={todo} onRemove={onRemove} checkPush = {checkPush}/>
))}
</div>


</div>
};

export default List;
28 changes: 28 additions & 0 deletions src/component/TodoThing.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
.TodoThing{
display: flex;
align-items: center;
gap: 20px;
padding-bottom: 20px;
border: 1px solid lightblue;
border-radius: 5px;
justify-content: space-between;
}

.TodoThing input{
cursor: pointer;
width: 30px;
}
.TodoThing .item{
cursor : pointer;
}

.TodoThing .item{
flex: 1;
}
.deletebtn{
border: 1px;
border-radius: 50px;
background: transparent;
border: none;
cursor: pointer;
}
28 changes: 28 additions & 0 deletions src/component/TodoThing.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import React, { useEffect, useState } from "react"
import "./TodoThing.css"
const TodoThing = ({todo, onRemove, checkPush}) => {
const [isChecked, setIsChecked] = useState(todo.isdone);
const removeHandler = () => {
onRemove(todo.id)
}

useEffect(() => {
setIsChecked(todo.isdone)
},[todo.isdone])

const checkHandler = () => {
checkPush(todo.id, todo.content)
setIsChecked(!isChecked)
}

return (
<div className="TodoThing">
<label>
<input type="checkbox" checked={isChecked} onChange={checkHandler} ></input>
<span className="item">{todo.content}</span>
</label>
<button className="deletebtn"onClick={removeHandler}>삭제</button>
</div>
)
}
export default TodoThing
13 changes: 13 additions & 0 deletions src/component/Todomaker.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.Todomaker{
display: flex;
}

.Todomaker input{
display: flex;
width: 100%;
padding : 20px;
border: 1px solid lightblue;
border-radius: 3px;
outline: none;
}

26 changes: 26 additions & 0 deletions src/component/Todomaker.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import React, {useState} from "react";
import "./Todomaker.css"


const Todomaker = ({addNewTodo}) => {

const [inputvalue, setinputvalue] = useState('')

const handleChange = (e) => setinputvalue(e.target.value);
const handleSubmit = (e) => {
e.preventDefault();
if (inputvalue === "") alert("할 일을 입력하세요📝");
else {
addNewTodo(inputvalue);
setinputvalue("");
}
};

return (
<form className="Todomaker" onSubmit={handleSubmit}>
<input type="text" value={inputvalue} onChange={handleChange} placeholder="할 일을 입력하세요" />
</form>
);
};

export default Todomaker;
Empty file removed src/main.js
Empty file.
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true
},
"include": ["src"],
"include": ["src", "App.jsx"],
"references": [{ "path": "./tsconfig.node.json" }]
}