-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
62f25ae
commit aa3fcdc
Showing
5 changed files
with
83 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { createSlice } from '@reduxjs/toolkit'; | ||
|
||
const filterInitialState = { | ||
brand: '', | ||
price: '', | ||
mileage: { from: '', to: '' }, | ||
}; | ||
|
||
const filtersSlice = createSlice({ | ||
name: 'filters', | ||
initialState: filterInitialState, | ||
reducers: { | ||
setAdvertsFilter(state, action) { | ||
return (state = { ...state, ...action.payload }); | ||
}, | ||
}, | ||
}); | ||
|
||
export const filtersReducer = filtersSlice.reducer; | ||
export const { setAdvertsFilter } = filtersSlice.actions; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const selectAdvertsFilter = state => state.filters; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,40 @@ | ||
import { configureStore } from '@reduxjs/toolkit'; | ||
import { setupListeners } from '@reduxjs/toolkit/query'; | ||
import { configureStore, combineReducers } from '@reduxjs/toolkit'; | ||
import storage from 'redux-persist/lib/storage'; | ||
import { | ||
persistStore, | ||
persistReducer, | ||
FLUSH, | ||
REHYDRATE, | ||
PAUSE, | ||
PERSIST, | ||
PURGE, | ||
REGISTER, | ||
} from 'redux-persist'; | ||
|
||
import { filtersReducer } from './filtersSlice'; | ||
import { carsApi } from './operations'; | ||
|
||
export const store = configureStore({ | ||
reducer: { | ||
[carsApi.reducerPath]: carsApi.reducer, | ||
}, | ||
const reducers = combineReducers({ | ||
[carsApi.reducerPath]: carsApi.reducer, | ||
filters: filtersReducer, | ||
}); | ||
|
||
const persistConfig = { | ||
key: 'root', | ||
version: 1, | ||
storage, | ||
}; | ||
|
||
const persistedReducer = persistReducer(persistConfig, reducers); | ||
|
||
export const store = configureStore({ | ||
reducer: persistedReducer, | ||
middleware: getDefaultMiddleware => | ||
getDefaultMiddleware().concat(carsApi.middleware), | ||
getDefaultMiddleware({ | ||
serializableCheck: { | ||
ignoredActions: [FLUSH, REHYDRATE, PAUSE, PERSIST, PURGE, REGISTER], | ||
}, | ||
}).concat(carsApi.middleware), | ||
}); | ||
|
||
setupListeners(store.dispatch); | ||
export let persistor = persistStore(store); |