Skip to content

Commit b236a54

Browse files
author
Rankvet-Developer
committed
toogle todo features added
1 parent 983dc15 commit b236a54

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

src/components/Todo.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
import cancelImage from "../assets/images/cancel.png";
2-
import { useDeleteTodoMutation } from '../features/api/apiSlice';
2+
import { useDeleteTodoMutation, useToogleTodoMutation } from '../features/api/apiSlice';
33

44
export default function Todo({ todo }) {
55

6-
const [deleteTodo,{isLoading,isError}] = useDeleteTodoMutation()
6+
const [deleteTodo] = useDeleteTodoMutation();
7+
const [toogleTodo,] = useToogleTodoMutation();
78

89

910
const { text, id, completed, color } = todo;
1011

11-
// const handleStatusChange = (todoId) => {
12-
// dispatch(updateStatus(todoId, completed));
13-
// };
12+
const handleStatusChange = (todoId) => {
13+
toogleTodo({id: todoId,toogleValue: completed});
14+
};
1415

1516
// const handleColorChange = (todoId, color) => {
1617
// dispatch(updateColor(todoId, color));
@@ -31,7 +32,7 @@ export default function Todo({ todo }) {
3132
<input
3233
type="checkbox"
3334
checked={completed}
34-
// onChange={() => handleStatusChange(id)}
35+
onChange={() => handleStatusChange(id)}
3536
className="opacity-0 absolute rounded-full"
3637
/>
3738
{completed && (

src/components/TodoList.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export default function TodoList() {
66
const {data:todos,isLoading,isError} = useGetTodosQuery();
77

88
let content = null;
9+
910
// decide what to render
1011
if(isLoading){
1112
content = <div>Loading...</div>

src/features/api/apiSlice.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,15 @@ export const apiSlice = createApi({
3434
url: `/todos/${id}`,
3535
method: "DELETE"
3636
})
37+
}),
38+
toogleTodo: builder.mutation({
39+
query:({id,toogleValue}) => ({
40+
url: `/todos/${id}`,
41+
method: "PATCH",
42+
body:{
43+
completed: !toogleValue
44+
}
45+
})
3746
})
3847
})
3948
})
@@ -42,5 +51,6 @@ export const {
4251
useAddTodoMutation,
4352
useGetTodosQuery,
4453
useUpdateTodoMutation,
45-
useDeleteTodoMutation
54+
useDeleteTodoMutation,
55+
useToogleTodoMutation
4656
} = apiSlice;

0 commit comments

Comments
 (0)