Skip to content

Commit 7dec74e

Browse files
author
Rankvet-Developer
committedSep 11, 2022
filter reducer added
1 parent a60e4de commit 7dec74e

File tree

4 files changed

+43
-4
lines changed

4 files changed

+43
-4
lines changed
 

‎src/app/store.js‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import { configureStore } from '@reduxjs/toolkit';
22
import { apiSlice } from '../features/api/apiSlice';
33
import counterReducer from '../features/counter/counterSlice';
4+
import filterReducer from '../features/filter/filterSlice';
45

56
export const store = configureStore({
67
reducer: {
78
counter: counterReducer,
8-
[apiSlice.reducerPath]: apiSlice.reducer
9+
[apiSlice.reducerPath]: apiSlice.reducer,
10+
filter: filterReducer
911
},
1012
middleware: (getDefaultMiddlewares) =>
1113
getDefaultMiddlewares().concat(apiSlice.middleware),

‎src/components/TodoList.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import Todo from "./Todo";
44
export default function TodoList() {
55
// use rtk query
66
const {data:todos,isLoading,isError} = useGetTodosQuery();
7-
7+
88
let content = null;
99

1010
// decide what to render

‎src/features/api/apiSlice.js‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export const apiSlice = createApi({
2121
queryString = "completed=false&";
2222
}
2323
if(status === "Complete"){
24-
queryString = "completed=false&";
24+
queryString = "completed=true&";
2525
}
2626
}
2727

@@ -35,7 +35,14 @@ export const apiSlice = createApi({
3535
method: 'get'
3636
}
3737
},
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"]
3946
}),
4047
addTodo: builder.mutation({
4148
query: (data) => ({

‎src/features/filter/filterSlice.js‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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;

0 commit comments

Comments
 (0)
Please sign in to comment.