forked from Untoc-Web-Develop/todo-list
-
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.
- Loading branch information
1 parent
6160ca2
commit ccce4db
Showing
13 changed files
with
221 additions
and
34 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
Binary file not shown.
Binary file not shown.
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 |
---|---|---|
@@ -1,7 +1,15 @@ | ||
import React from 'react'; | ||
import InputForm from 'components/InputForm'; | ||
import TodoList from 'components/TodoList'; | ||
|
||
function App() { | ||
return <h1 className="text-3xl font-bold underline">Hello, World!</h1>; | ||
return ( | ||
<div> | ||
<h1>니할일이뭔데그래서...</h1> | ||
<InputForm /> | ||
<TodoList /> | ||
</div> | ||
); | ||
} | ||
|
||
export default App; |
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,30 @@ | ||
export const ADD = 'ADD_TODO'; | ||
export const DELETE = 'DELETE_TODO'; | ||
export const TOGGLE = 'TOGGLE_TODO'; | ||
|
||
let prevId = 0; | ||
|
||
export const addTodo = (todo) => { | ||
return { | ||
type: ADD, | ||
todo: { | ||
id: prevId++, | ||
text: todo.text, | ||
done: todo.done, | ||
}, | ||
}; | ||
}; | ||
|
||
export const deleteTodo = (id) => { | ||
return { | ||
type: DELETE, | ||
id, | ||
}; | ||
}; | ||
|
||
export const toggleTodo = (id) => { | ||
return { | ||
type: TOGGLE, | ||
id, | ||
}; | ||
}; |
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 @@ | ||
import { ADD, DELETE, TOGGLE } from './actions'; | ||
|
||
const initialState = { | ||
todos: [], | ||
}; | ||
|
||
export const reducer = (state = initialState, action) => { | ||
switch (action.type) { | ||
case ADD: | ||
return { | ||
todos: [...state.todos, action.todo], | ||
}; | ||
|
||
case TOGGLE: | ||
return { | ||
...state, | ||
todos: state.todos.map((todo) => (todo.id === action.id ? { ...todo, done: !todo.done } : todo)), | ||
}; | ||
|
||
case DELETE: | ||
return { | ||
todos: [...state.todos.filter((todo) => todo.id !== action.id)], | ||
}; | ||
|
||
default: | ||
return state; | ||
} | ||
}; |
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,47 @@ | ||
import React, { useState } from 'react'; | ||
import { useDispatch } from 'react-redux'; | ||
import { addTodo } from 'common/actions'; | ||
|
||
const InputForm = () => { | ||
const dispatch = useDispatch(); | ||
|
||
const [content, setContent] = useState(''); | ||
|
||
const handleChange = (e) => { | ||
const { value } = e.target; | ||
setContent(value); | ||
}; | ||
|
||
const handleClick = () => { | ||
const todo = { | ||
text: content, | ||
done: false, | ||
}; | ||
|
||
dispatch(addTodo(todo)); | ||
setContent(''); | ||
}; | ||
|
||
const handleKeypress = (e) => { | ||
if (e.key === 'Enter') { | ||
handleClick(); | ||
} | ||
}; | ||
|
||
return ( | ||
<div> | ||
<input | ||
type="text" | ||
placeholder="할 일이 먼데" | ||
onChange={handleChange} | ||
value={content} | ||
onKeyDown={handleKeypress} | ||
/> | ||
<button onClick={handleClick} type="submit"> | ||
+ | ||
</button> | ||
</div> | ||
); | ||
}; | ||
|
||
export default InputForm; |
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,45 @@ | ||
import React from 'react'; | ||
import { useDispatch } from 'react-redux'; | ||
import PropTypes from 'prop-types'; | ||
import { MdCheckBox, MdCheckBoxOutlineBlank } from 'react-icons/md'; | ||
import { deleteTodo, toggleTodo } from 'common/actions'; | ||
|
||
const TodoItem = ({ todo }) => { | ||
const dispatch = useDispatch(); | ||
|
||
const { id, text, done } = todo; | ||
|
||
const handleClick = () => { | ||
dispatch(deleteTodo(id)); | ||
}; | ||
|
||
const handleCheckboxChange = () => { | ||
dispatch(toggleTodo(id)); | ||
}; | ||
|
||
return ( | ||
<div> | ||
<div className="check-box"> | ||
{done ? ( | ||
<MdCheckBox onClick={handleCheckboxChange} /> | ||
) : ( | ||
<MdCheckBoxOutlineBlank onClick={handleCheckboxChange} /> | ||
)} | ||
</div> | ||
<span>{text}</span> | ||
<button onClick={handleClick} type="button"> | ||
안해!!! | ||
</button> | ||
</div> | ||
); | ||
}; | ||
|
||
TodoItem.propTypes = { | ||
todo: PropTypes.shape({ | ||
id: PropTypes.number.isRequired, | ||
text: PropTypes.string.isRequired, | ||
done: PropTypes.bool.isRequired, | ||
}).isRequired, | ||
}; | ||
|
||
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,17 @@ | ||
import React from 'react'; | ||
import { useSelector } from 'react-redux'; | ||
import TodoItem from './TodoItem'; | ||
|
||
const TodoList = () => { | ||
const todos = useSelector((state) => state.todos); | ||
|
||
return ( | ||
<div> | ||
{todos.map((todo) => ( | ||
<TodoItem key={todo.id} todo={todo} /> | ||
))} | ||
</div> | ||
); | ||
}; | ||
|
||
export default TodoList; |
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 |
---|---|---|
@@ -1,7 +1,17 @@ | ||
import React from 'react'; | ||
import { createStore } from 'redux'; | ||
import ReactDOM from 'react-dom/client'; | ||
|
||
import './index.css'; | ||
import { Provider } from 'react-redux'; | ||
import { reducer } from './common/reducer'; | ||
import App from './App'; | ||
|
||
const reduxStore = createStore(reducer); | ||
const root = ReactDOM.createRoot(document.getElementById('root')); | ||
root.render(<App />); | ||
|
||
root.render( | ||
<Provider store={reduxStore}> | ||
<App /> | ||
</Provider>, | ||
); |