mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2026-07-20 18:51:53 +00:00
Created single reducer to handle settings
This commit is contained in:
@@ -3,16 +3,20 @@ import PropTypes from 'prop-types';
|
||||
|
||||
export const LOAD_REAL_TIME_UPDATES = 'shlink/realTimeUpdates/LOAD_REAL_TIME_UPDATES';
|
||||
|
||||
export const RealTimeUpdatesType = PropTypes.shape({
|
||||
enabled: PropTypes.bool.isRequired,
|
||||
export const SettingsType = PropTypes.shape({
|
||||
realTimeUpdates: PropTypes.shape({
|
||||
enabled: PropTypes.bool.isRequired,
|
||||
}),
|
||||
});
|
||||
|
||||
const initialState = {
|
||||
enabled: true,
|
||||
realTimeUpdates: {
|
||||
enabled: true,
|
||||
},
|
||||
};
|
||||
|
||||
export default handleActions({
|
||||
[LOAD_REAL_TIME_UPDATES]: (state, { enabled }) => ({ ...state, enabled }),
|
||||
[LOAD_REAL_TIME_UPDATES]: (state, { realTimeUpdates }) => ({ ...state, realTimeUpdates }),
|
||||
}, initialState);
|
||||
|
||||
export const setRealTimeUpdates = ({ updateSettings }, loadRealTimeUpdatesAction) => (enabled) => {
|
||||
@@ -23,10 +27,9 @@ export const setRealTimeUpdates = ({ updateSettings }, loadRealTimeUpdatesAction
|
||||
|
||||
export const loadRealTimeUpdates = ({ loadSettings }) => () => {
|
||||
const { realTimeUpdates = {} } = loadSettings();
|
||||
const { enabled = true } = realTimeUpdates;
|
||||
|
||||
return {
|
||||
type: LOAD_REAL_TIME_UPDATES,
|
||||
enabled,
|
||||
realTimeUpdates,
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user