2020-08-31 23:11:30 +02:00
|
|
|
import { createSlice } from '@reduxjs/toolkit';
|
|
|
|
|
|
|
|
const websites = createSlice({
|
2020-09-03 01:49:14 +02:00
|
|
|
name: 'websites',
|
2020-08-31 23:11:30 +02:00
|
|
|
initialState: {},
|
|
|
|
reducers: {
|
|
|
|
updateWebsites(state, action) {
|
|
|
|
state = action.payload;
|
|
|
|
return state;
|
|
|
|
},
|
2020-09-03 01:49:14 +02:00
|
|
|
updateWebsite(state, action) {
|
|
|
|
const { websiteId, ...data } = action.payload;
|
|
|
|
state[websiteId] = data;
|
|
|
|
return state;
|
|
|
|
},
|
2020-08-31 23:11:30 +02:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2020-09-03 01:49:14 +02:00
|
|
|
export const { updateWebsites, updateWebsite } = websites.actions;
|
2020-08-31 23:11:30 +02:00
|
|
|
|
|
|
|
export default websites.reducer;
|
|
|
|
|
|
|
|
export function setDateRange(websiteId, dateRange) {
|
2020-09-03 01:49:14 +02:00
|
|
|
return dispatch => {
|
|
|
|
return dispatch(
|
|
|
|
updateWebsite({ websiteId, dateRange: { ...dateRange, modified: Date.now() } }),
|
|
|
|
);
|
2020-08-31 23:11:30 +02:00
|
|
|
};
|
|
|
|
}
|