File tree Expand file tree Collapse file tree 3 files changed +19
-7
lines changed Expand file tree Collapse file tree 3 files changed +19
-7
lines changed Original file line number Diff line number Diff line change 1
1
import cancelImage from "../assets/images/cancel.png" ;
2
- import { useDeleteTodoMutation } from '../features/api/apiSlice' ;
2
+ import { useDeleteTodoMutation , useToogleTodoMutation } from '../features/api/apiSlice' ;
3
3
4
4
export default function Todo ( { todo } ) {
5
5
6
- const [ deleteTodo , { isLoading, isError} ] = useDeleteTodoMutation ( )
6
+ const [ deleteTodo ] = useDeleteTodoMutation ( ) ;
7
+ const [ toogleTodo , ] = useToogleTodoMutation ( ) ;
7
8
8
9
9
10
const { text, id, completed, color } = todo ;
10
11
11
- // const handleStatusChange = (todoId) => {
12
- // dispatch(updateStatus( todoId, completed) );
13
- // };
12
+ const handleStatusChange = ( todoId ) => {
13
+ toogleTodo ( { id : todoId , toogleValue : completed } ) ;
14
+ } ;
14
15
15
16
// const handleColorChange = (todoId, color) => {
16
17
// dispatch(updateColor(todoId, color));
@@ -31,7 +32,7 @@ export default function Todo({ todo }) {
31
32
< input
32
33
type = "checkbox"
33
34
checked = { completed }
34
- // onChange={() => handleStatusChange(id)}
35
+ onChange = { ( ) => handleStatusChange ( id ) }
35
36
className = "opacity-0 absolute rounded-full"
36
37
/>
37
38
{ completed && (
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ export default function TodoList() {
6
6
const { data :todos , isLoading, isError} = useGetTodosQuery ( ) ;
7
7
8
8
let content = null ;
9
+
9
10
// decide what to render
10
11
if ( isLoading ) {
11
12
content = < div > Loading...</ div >
Original file line number Diff line number Diff line change @@ -34,6 +34,15 @@ export const apiSlice = createApi({
34
34
url : `/todos/${ id } ` ,
35
35
method : "DELETE"
36
36
} )
37
+ } ) ,
38
+ toogleTodo : builder . mutation ( {
39
+ query :( { id, toogleValue} ) => ( {
40
+ url : `/todos/${ id } ` ,
41
+ method : "PATCH" ,
42
+ body :{
43
+ completed : ! toogleValue
44
+ }
45
+ } )
37
46
} )
38
47
} )
39
48
} )
@@ -42,5 +51,6 @@ export const {
42
51
useAddTodoMutation,
43
52
useGetTodosQuery,
44
53
useUpdateTodoMutation,
45
- useDeleteTodoMutation
54
+ useDeleteTodoMutation,
55
+ useToogleTodoMutation
46
56
} = apiSlice ;
You can’t perform that action at this time.
0 commit comments