mirror of
https://github.com/umami-software/umami.git
synced 2026-02-12 00:27:11 +01:00
Move date range selection into redux.
This commit is contained in:
parent
d06c077019
commit
c5cb19a3bf
21 changed files with 141 additions and 138 deletions
34
redux/actions/websites.js
Normal file
34
redux/actions/websites.js
Normal 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));
|
||||
};
|
||||
}
|
||||
|
|
@ -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 });
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue