You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
816 B
40 lines
816 B
4 years ago
|
import { createSlice } from '@reduxjs/toolkit';
|
||
5 years ago
|
|
||
4 years ago
|
import { ASSET_ROUTE, DEFAULT_ROUTE } from '../../helpers/constants/routes';
|
||
5 years ago
|
|
||
|
// Constants
|
||
|
|
||
|
const initialState = {
|
||
|
mostRecentOverviewPage: DEFAULT_ROUTE,
|
||
4 years ago
|
};
|
||
5 years ago
|
|
||
4 years ago
|
const name = 'history';
|
||
5 years ago
|
|
||
|
// Slice (reducer plus auto-generated actions and action creators)
|
||
|
|
||
|
const slice = createSlice({
|
||
|
name,
|
||
|
initialState,
|
||
|
reducers: {
|
||
|
pageChanged: (state, action) => {
|
||
4 years ago
|
const path = action.payload;
|
||
5 years ago
|
if (path === DEFAULT_ROUTE || path.startsWith(ASSET_ROUTE)) {
|
||
4 years ago
|
state.mostRecentOverviewPage = path;
|
||
5 years ago
|
}
|
||
|
},
|
||
|
},
|
||
4 years ago
|
});
|
||
5 years ago
|
|
||
4 years ago
|
const { actions, reducer } = slice;
|
||
5 years ago
|
|
||
4 years ago
|
export default reducer;
|
||
5 years ago
|
|
||
|
// Selectors
|
||
|
|
||
4 years ago
|
export const getMostRecentOverviewPage = (state) =>
|
||
4 years ago
|
state[name].mostRecentOverviewPage;
|
||
5 years ago
|
|
||
|
// Actions / action-creators
|
||
|
|
||
4 years ago
|
export const { pageChanged } = actions;
|