Created settings page and reducers to handle real-time updates config

This commit is contained in:
Alejandro Celaya
2020-04-25 09:49:54 +02:00
parent 7516ca8dd9
commit 41f885d8ec
9 changed files with 131 additions and 18 deletions

View File

@@ -0,0 +1,32 @@
import { handleActions } from 'redux-actions';
import PropTypes from 'prop-types';
const LOAD_REAL_TIME_UPDATES = 'shlink/realTimeUpdates/LOAD_REAL_TIME_UPDATES';
export const RealTimeUpdatesType = PropTypes.shape({
enabled: PropTypes.bool.isRequired,
});
const initialState = {
enabled: true,
};
export default handleActions({
[LOAD_REAL_TIME_UPDATES]: (state, { enabled }) => ({ ...state, enabled }),
}, initialState);
export const setRealTimeUpdates = ({ updateSettings }, loadRealTimeUpdatesAction) => (enabled) => {
updateSettings({ realTimeUpdates: { enabled } });
return loadRealTimeUpdatesAction();
};
export const loadRealTimeUpdates = ({ loadSettings }) => () => {
const { realTimeUpdates = {} } = loadSettings();
const { enabled = true } = realTimeUpdates;
return {
type: LOAD_REAL_TIME_UPDATES,
enabled,
};
};