-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[week2/mission] ToDo List (React) 구현
- Loading branch information
Showing
33 changed files
with
4,826 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
pnpm-debug.log* | ||
lerna-debug.log* | ||
|
||
node_modules | ||
dist | ||
dist-ssr | ||
*.local | ||
|
||
# Editor directories and files | ||
.vscode/* | ||
!.vscode/extensions.json | ||
.idea | ||
.DS_Store | ||
*.suo | ||
*.ntvs* | ||
*.njsproj | ||
*.sln | ||
*.sw? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
pnpm-debug.log* | ||
lerna-debug.log* | ||
|
||
node_modules | ||
dist | ||
dist-ssr | ||
*.local | ||
|
||
# Editor directories and files | ||
.vscode/* | ||
!.vscode/extensions.json | ||
.idea | ||
.DS_Store | ||
*.suo | ||
*.ntvs* | ||
*.njsproj | ||
*.sln | ||
*.sw? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# React + Vite | ||
|
||
This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules. | ||
|
||
Currently, two official plugins are available: | ||
|
||
- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh | ||
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import js from '@eslint/js' | ||
import globals from 'globals' | ||
import react from 'eslint-plugin-react' | ||
import reactHooks from 'eslint-plugin-react-hooks' | ||
import reactRefresh from 'eslint-plugin-react-refresh' | ||
|
||
export default [ | ||
{ ignores: ['dist'] }, | ||
{ | ||
files: ['**/*.{js,jsx}'], | ||
languageOptions: { | ||
ecmaVersion: 2020, | ||
globals: globals.browser, | ||
parserOptions: { | ||
ecmaVersion: 'latest', | ||
ecmaFeatures: { jsx: true }, | ||
sourceType: 'module', | ||
}, | ||
}, | ||
settings: { react: { version: '18.3' } }, | ||
plugins: { | ||
react, | ||
'react-hooks': reactHooks, | ||
'react-refresh': reactRefresh, | ||
}, | ||
rules: { | ||
...js.configs.recommended.rules, | ||
...react.configs.recommended.rules, | ||
...react.configs['jsx-runtime'].rules, | ||
...reactHooks.configs.recommended.rules, | ||
'react/jsx-no-target-blank': 'off', | ||
'react-refresh/only-export-components': [ | ||
'warn', | ||
{ allowConstantExport: true }, | ||
], | ||
}, | ||
}, | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<link rel="icon" type="image/svg+xml" href="/vite.svg" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>Vite + React</title> | ||
</head> | ||
<body> | ||
<div id="root"></div> | ||
<script type="module" src="/src/main.jsx"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"name": "first-react", | ||
"private": true, | ||
"version": "0.0.0", | ||
"type": "module", | ||
"scripts": { | ||
"dev": "vite", | ||
"build": "vite build", | ||
"lint": "eslint .", | ||
"preview": "vite preview" | ||
}, | ||
"dependencies": { | ||
"react": "^18.3.1", | ||
"react-dom": "^18.3.1" | ||
}, | ||
"devDependencies": { | ||
"@eslint/js": "^9.9.0", | ||
"@types/react": "^18.3.3", | ||
"@types/react-dom": "^18.3.0", | ||
"@vitejs/plugin-react-swc": "^3.5.0", | ||
"eslint": "^9.9.0", | ||
"eslint-plugin-react": "^7.35.0", | ||
"eslint-plugin-react-hooks": "^5.1.0-rc.0", | ||
"eslint-plugin-react-refresh": "^0.4.9", | ||
"globals": "^15.9.0", | ||
"vite": "^5.4.1" | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
.form { | ||
display: flex; | ||
gap: 10px; | ||
margin-bottom: 20px; | ||
} | ||
|
||
.todo-list { | ||
list-style-type: none; | ||
padding: 0; | ||
} | ||
|
||
.todo-item { | ||
display: flex; | ||
margin-bottom: 10px; | ||
justify-content: space-between; | ||
align-items: center; | ||
width: 350px; | ||
} | ||
|
||
.todo-item-text { | ||
display: flex; | ||
flex-grow: 1; | ||
} | ||
|
||
.todo-item-buttons { | ||
display: flex; | ||
gap: 10px; | ||
} | ||
|
||
.app-container { | ||
width: 100vw; | ||
height: 100vh; | ||
display: flex; | ||
flex-direction: column; | ||
justify-content: center; | ||
align-items: center; | ||
background-color: ghostwhite; | ||
} | ||
|
||
button { | ||
background-color: aliceblue; | ||
display: flex; | ||
gap: 10px; | ||
} | ||
|
||
.todo-item-text-id { | ||
margin-right: 10px; | ||
} | ||
|
||
.todo-input { | ||
width: 300px; | ||
text-align: center; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { useState } from "react"; | ||
import ToDoForm from "./component/ToDoForm"; | ||
import ToDoList from "./component/ToDoList"; | ||
import "./App.css"; | ||
|
||
function App() { | ||
// 투두리스트, 화면에 출력되는 (추가, 삭제, 수정) | ||
const [toDos, setToDos] = useState([ | ||
{ id: 1, task: "투두 만들어보기" }, | ||
{ id: 2, task: "희연 혜원 혜윤 건 찬민" }, | ||
]); | ||
// | ||
const [text, setText] = useState(""); | ||
// 랜더링 방지 | ||
const handleSubmit = (event) => { | ||
event.preventDefault(); | ||
}; | ||
|
||
// 1. 추가하기 | ||
const addToDo = () => { | ||
if (text.trim().length === 0) return; | ||
setToDos((prev) => [ | ||
...prev, | ||
{ id: Math.floor(Math.random() * 100) + 2, task: text }, | ||
]); | ||
setText(""); | ||
}; | ||
|
||
// 2. 삭제하기 | ||
const deleteToDo = (id) => { | ||
setToDos((prev) => prev.filter((todo) => todo.id !== id)); | ||
}; | ||
// 3. 수정하기 | ||
const [editingId, setEditingId] = useState(""); | ||
const [editText, setEditText] = useState(""); | ||
const updateToDo = (id, text) => { | ||
setToDos((prev) => | ||
prev.map((item) => (item.id === id ? { ...item, task: text } : item)) | ||
); | ||
setEditingId(""); // input을 텍스트로 다시 돌려놓기 | ||
}; | ||
return ( | ||
<div className="app-container"> | ||
<ToDoForm text={text} setText={setText} addToDo={addToDo} /> | ||
<ToDoList | ||
toDos={toDos} | ||
deleteToDo={deleteToDo} | ||
setEditingId={setEditingId} | ||
editingId={editingId} | ||
updateToDo={updateToDo} | ||
editText={editText} | ||
setEditText={setEditText} | ||
/> | ||
</div> | ||
); | ||
} | ||
|
||
export default App; |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import React, { useState } from "react"; | ||
|
||
function ToDoForm({ text, setText, addToDo }) { | ||
return ( | ||
<form className="form" onSubmit={(e) => e.preventDefault()}> | ||
<input | ||
className="todo-input" | ||
type="text" | ||
value={text} | ||
onChange={(e) => setText(e.target.value)} | ||
placeholder="오늘의 할 일은 무엇이 있나요?" | ||
/> | ||
<button onClick={addToDo}>할 일 등록</button> | ||
</form> | ||
); | ||
} | ||
|
||
export default ToDoForm; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import React, { useState } from "react"; | ||
|
||
function ToDoItem({ | ||
todo, | ||
deleteToDo, | ||
setEditingId, | ||
editingId, | ||
updateToDo, | ||
editText, | ||
setEditText, | ||
}) { | ||
return ( | ||
<li className="todo-item "> | ||
{editingId !== todo.id ? ( | ||
<div className="todo-item-text"> | ||
<p className="todo-item-text-id">{todo.id}. </p> | ||
<p>{todo.task}</p> | ||
</div> | ||
) : ( | ||
<div className="todo-item-text"> | ||
<p>{todo.id}. </p> | ||
<input | ||
defaultValue={todo.task} | ||
onChange={(e) => setEditText(e.target.value)} | ||
/> | ||
</div> | ||
)} | ||
<div className="todo-item-buttons"> | ||
<button onClick={() => deleteToDo(todo.id)}>삭제하기</button> | ||
{editingId === todo.id ? ( | ||
<button onClick={() => updateToDo(todo.id, editText)}> | ||
수정 완료 | ||
</button> | ||
) : ( | ||
<button onClick={() => setEditingId(todo.id)}>수정 진행</button> | ||
)} | ||
</div> | ||
</li> | ||
); | ||
} | ||
|
||
export default ToDoItem; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import React, { useState } from "react"; | ||
import ToDoItem from "./ToDoItem"; | ||
|
||
function ToDoList({ | ||
toDos, | ||
deleteToDo, | ||
setEditingId, | ||
editingId, | ||
updateToDo, | ||
editText, | ||
setEditText, | ||
}) { | ||
return ( | ||
<ul className="todo-list"> | ||
{toDos.map((todo) => ( | ||
<ToDoItem | ||
key={todo.id} | ||
todo={todo} | ||
deleteToDo={deleteToDo} | ||
setEditingId={setEditingId} | ||
editingId={editingId} | ||
updateToDo={updateToDo} | ||
editText={editText} | ||
setEditText={setEditText} | ||
/> | ||
))} | ||
</ul> | ||
); | ||
} | ||
|
||
export default ToDoList; |
Empty file.
Oops, something went wrong.