Move date range selection into redux.
This commit is contained in:
34
redux/actions/websites.js
Normal file
34
redux/actions/websites.js
Normal file
@@ -0,0 +1,34 @@
|
||||
import { createSlice } from '@reduxjs/toolkit';
|
||||
import produce from 'immer';
|
||||
|
||||
const websites = createSlice({
|
||||
name: 'user',
|
||||
initialState: {},
|
||||
reducers: {
|
||||
updateWebsites(state, action) {
|
||||
state = action.payload;
|
||||
return state;
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
export const { updateWebsites } = websites.actions;
|
||||
|
||||
export default websites.reducer;
|
||||
|
||||
export function setDateRange(websiteId, dateRange) {
|
||||
return (dispatch, getState) => {
|
||||
const state = getState();
|
||||
let { websites = {} } = state;
|
||||
|
||||
websites = produce(websites, draft => {
|
||||
if (!draft[websiteId]) {
|
||||
draft[websiteId] = {};
|
||||
}
|
||||
dateRange.modified = Date.now();
|
||||
draft[websiteId].dateRange = dateRange;
|
||||
});
|
||||
|
||||
return dispatch(updateWebsites(websites));
|
||||
};
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
import { combineReducers } from 'redux';
|
||||
import user from './actions/user';
|
||||
import websites from './actions/websites';
|
||||
|
||||
export default combineReducers({ user });
|
||||
export default combineReducers({ user, websites });
|
||||
|
||||
Reference in New Issue
Block a user