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-11-24 13:21:44 +01:00
|
|
|
initialState: [],
|
2020-08-31 23:11:30 +02:00
|
|
|
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
|
|
|
};
|
|
|
|
}
|
2020-11-24 13:21:44 +01:00
|
|
|
|
|
|
|
export function setWebsitesData(data) {
|
|
|
|
return dispatch => {
|
|
|
|
return dispatch(updateWebsites([...data]));
|
|
|
|
};
|
|
|
|
}
|