diff --git a/src/components/AddTodo/index.js b/src/components/AddTodo/index.js index b427633..d2ded3d 100644 --- a/src/components/AddTodo/index.js +++ b/src/components/AddTodo/index.js @@ -1,9 +1,11 @@ import React, { useState } from 'react'; import { useDispatch } from 'react-redux'; import { saveTodo } from '../../features/todoSlice'; +import Checkbox from '../Checkbox'; const AddTodo = () => { const [todoText, setTodoText] = useState(''); + const [check, setCheck] = useState(false); const dispatch = useDispatch(); const handleSubmit = (e) => { e.preventDefault(); @@ -11,14 +13,18 @@ const AddTodo = () => { dispatch( saveTodo({ text: todoText, - done: false, + done: check, id: Date.now(), }) ); }; return (
); }; diff --git a/src/components/Checkbox/index.js b/src/components/Checkbox/index.js new file mode 100644 index 0000000..febef07 --- /dev/null +++ b/src/components/Checkbox/index.js @@ -0,0 +1,13 @@ +import React from 'react'; +import { useDispatch } from 'react-redux'; +import { setCheck } from '../../features/todoSlice'; + +const Checkbox = ({ checked, id }) => { + const dispatch = useDispatch(); + const handleCheck = () => { + dispatch(setCheck(id)); + }; + return ; +}; + +export default Checkbox; diff --git a/src/components/Checkbox/style.css b/src/components/Checkbox/style.css new file mode 100644 index 0000000..e69de29 diff --git a/src/components/TodoItem/index.js b/src/components/TodoItem/index.js index 5378d11..b6ce134 100644 --- a/src/components/TodoItem/index.js +++ b/src/components/TodoItem/index.js @@ -1,6 +1,8 @@ import React from 'react'; import { useDispatch } from 'react-redux'; +import PropTypes from 'prop-types'; import { deleteTodo, setCheck } from '../../features/todoSlice'; +import Checkbox from '../Checkbox'; const TodoItem = ({ text, done, id }) => { const dispatch = useDispatch(); @@ -9,13 +11,12 @@ const TodoItem = ({ text, done, id }) => { }; const handleClick = () => { - console.log(dispatch(deleteTodo(id))); dispatch(deleteTodo(id)); }; return (