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-04-07 14:10:03 +00:00
|
|
|
import { defaultSettings } from '../lib/constants';
|
2022-05-03 01:27:33 +00:00
|
|
|
import { IAssetsFavicon512 } from '../definitions/IAssetsFavicon512';
|
2020-04-01 19:24:42 +00:00
|
|
|
|
2022-04-07 14:10:03 +00:00
|
|
|
export type TSupportedSettings = keyof typeof defaultSettings;
|
2022-05-03 01:27:33 +00:00
|
|
|
export type TSettingsValues = string | number | boolean | string[] | IAssetsFavicon512;
|
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;
|
|
|
|
}
|
|
|
|
};
|