umami/redux/actions/websites.js

30 lines
683 B
JavaScript
Raw Normal View History

2020-08-31 23:11:30 +02:00
import { createSlice } from '@reduxjs/toolkit';
const websites = createSlice({
name: 'websites',
2020-08-31 23:11:30 +02:00
initialState: {},
reducers: {
updateWebsites(state, action) {
state = action.payload;
return state;
},
updateWebsite(state, action) {
const { websiteId, ...data } = action.payload;
state[websiteId] = data;
return state;
},
2020-08-31 23:11:30 +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) {
return dispatch => {
return dispatch(
updateWebsite({ websiteId, dateRange: { ...dateRange, modified: Date.now() } }),
);
2020-08-31 23:11:30 +02:00
};
}