umami/redux/actions/websites.js

36 lines
802 B
JavaScript
Raw Normal View History

2020-08-31 23:11:30 +02:00
import { createSlice } from '@reduxjs/toolkit';
const websites = createSlice({
name: 'websites',
initialState: [],
2020-08-31 23:11:30 +02:00
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
};
}
export function setWebsitesData(data) {
return dispatch => {
return dispatch(updateWebsites([...data]));
};
}