Move date range selection into redux.

This commit is contained in:
Mike Cao 2020-08-31 14:11:30 -07:00
parent d06c077019
commit c5cb19a3bf
21 changed files with 141 additions and 138 deletions

34
redux/actions/websites.js Normal file
View 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));
};
}

View file

@ -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 });