Rocket.Chat.ReactNative/app/reducers/settings.ts

32 lines
788 B
TypeScript
Raw Normal View History

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