2022-01-14 21:00:04 +00:00
|
|
|
import { IActionSettings } from '../actions/settings';
|
2020-04-01 19:24:42 +00:00
|
|
|
import { SETTINGS } from '../actions/actionsTypes';
|
2022-03-02 14:49:43 +00:00
|
|
|
import settings from '../constants/settings';
|
2020-04-01 19:24:42 +00:00
|
|
|
|
2022-03-02 14:49:43 +00:00
|
|
|
export type TSupportedSettings = keyof typeof settings;
|
|
|
|
export type TSettingsValues = string | number | boolean | string[];
|
2022-01-20 17:41:04 +00:00
|
|
|
|
2022-03-02 14:49:43 +00:00
|
|
|
export type TSettingsState = {
|
|
|
|
[K in TSupportedSettings]?: TSettingsValues;
|
|
|
|
};
|
2020-04-01 19:24:42 +00:00
|
|
|
|
2022-03-02 14:49:43 +00:00
|
|
|
export const initialState: TSettingsState = {};
|
2022-01-14 21:00:04 +00:00
|
|
|
|
2022-03-02 14:49:43 +00:00
|
|
|
export default (state = initialState, action: IActionSettings): TSettingsState => {
|
2020-04-01 19:24:42 +00:00
|
|
|
switch (action.type) {
|
|
|
|
case SETTINGS.ADD:
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
...action.payload
|
|
|
|
};
|
2021-07-01 19:30:55 +00:00
|
|
|
case SETTINGS.UPDATE:
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
[action.payload.id]: action.payload.value
|
|
|
|
};
|
2020-04-01 19:24:42 +00:00
|
|
|
case SETTINGS.CLEAR:
|
|
|
|
return initialState;
|
|
|
|
default:
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
};
|