Skip to content

Commit

Permalink
Merge pull request #8 from GSG-G9/components
Browse files Browse the repository at this point in the history
fix delete function
  • Loading branch information
Israa91 authored Apr 28, 2021
2 parents 9733592 + 68fd13f commit a176868
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
6 changes: 3 additions & 3 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ function App() {
const todoList = useSelector(selectTodoList);
return (
<div className="app__container">
<div className="app__todoContainer">
<ul className="app__todoContainer">
{todoList.map((item) => (
<TodoItem text={item.text} done={item.done} id={item.id} />
<TodoItem text={item.text} done={item.done} id={item.id} key={item.id} />
))}
</div>
</ul>
<AddTodo />
</div>
);
Expand Down
17 changes: 8 additions & 9 deletions src/components/TodoItem/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,18 @@ const TodoItem = ({ text, done, id }) => {
};

const handleClick = () => {
console.log( dispatch(deleteTodo(id)));
console.log(dispatch(deleteTodo(id)));
dispatch(deleteTodo(id));
};
return (
<div className="todoItem">
<li className="todoItem">
<input type="checkbox" checked={done} onChange={handleCheck} />
<span>
<p className={done && 'todoItem--done'}>{text}</p>
<button type="button" onClick={handleClick}>
delete
</button>
</span>
</div>

<span className={done ? 'todoItem--done' : null}>{text}</span>
<button type="button" onClick={handleClick}>
delete
</button>
</li>
);
};

Expand Down
8 changes: 7 additions & 1 deletion src/features/todoSlice.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,13 @@ const todoSlice = createSlice({
});
},
deleteTodo: (state, action) => {
state.todoList.filter((item) => action.payload !== item.id);
const { todoList } = state;
const deleted = todoList.filter((item) => item.id !== action.payload);

return {
...state,
todoList: deleted,
};
},
},
});
Expand Down

0 comments on commit a176868

Please sign in to comment.