File tree Expand file tree Collapse file tree 4 files changed +43
-4
lines changed Expand file tree Collapse file tree 4 files changed +43
-4
lines changed Original file line number Diff line number Diff line change 1
1
import { configureStore } from '@reduxjs/toolkit' ;
2
2
import { apiSlice } from '../features/api/apiSlice' ;
3
3
import counterReducer from '../features/counter/counterSlice' ;
4
+ import filterReducer from '../features/filter/filterSlice' ;
4
5
5
6
export const store = configureStore ( {
6
7
reducer : {
7
8
counter : counterReducer ,
8
- [ apiSlice . reducerPath ] : apiSlice . reducer
9
+ [ apiSlice . reducerPath ] : apiSlice . reducer ,
10
+ filter : filterReducer
9
11
} ,
10
12
middleware : ( getDefaultMiddlewares ) =>
11
13
getDefaultMiddlewares ( ) . concat ( apiSlice . middleware ) ,
Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ import Todo from "./Todo";
4
4
export default function TodoList ( ) {
5
5
// use rtk query
6
6
const { data :todos , isLoading, isError} = useGetTodosQuery ( ) ;
7
-
7
+
8
8
let content = null ;
9
9
10
10
// decide what to render
Original file line number Diff line number Diff line change @@ -21,7 +21,7 @@ export const apiSlice = createApi({
21
21
queryString = "completed=false&" ;
22
22
}
23
23
if ( status === "Complete" ) {
24
- queryString = "completed=false &" ;
24
+ queryString = "completed=true &" ;
25
25
}
26
26
}
27
27
@@ -35,7 +35,14 @@ export const apiSlice = createApi({
35
35
method : 'get'
36
36
}
37
37
} ,
38
- providesTags : [ "Todos" ]
38
+ providesTags : ( result , error , arg ) => {
39
+ console . log ( result ) ;
40
+ return [
41
+ "Todos" ,
42
+ { type :"Todos" , id : arg . id }
43
+ ]
44
+ }
45
+ // invalidatesTags: ["Todos"]
39
46
} ) ,
40
47
addTodo : builder . mutation ( {
41
48
query : ( data ) => ( {
Original file line number Diff line number Diff line change
1
+ import { createSlice } from "@reduxjs/toolkit" ;
2
+
3
+ const initialState = {
4
+ status : "All" ,
5
+ colors : [ ]
6
+ }
7
+
8
+ const filterSlice = createSlice ( {
9
+ name : "filter" ,
10
+ initialState,
11
+ reducers :{
12
+ setStatus : ( state , action ) => {
13
+ state . status = action . payload ;
14
+ } ,
15
+ addColor : ( state , action ) => {
16
+ state . colors . push ( action . payload ) ;
17
+ } ,
18
+ removeColor : ( state , action ) => {
19
+ state . colors = state . colors . filter ( existingColor => existingColor !== action . payload ) ;
20
+ }
21
+ }
22
+ } )
23
+
24
+ export const {
25
+ setStatus,
26
+ addColor,
27
+ removeColor
28
+ } = filterSlice . actions ;
29
+
30
+ export default filterSlice . reducer ;
You can’t perform that action at this time.
0 commit comments