signal-desktop/ts/state/ducks/globalModals.ts

73 lines
1.6 KiB
TypeScript
Raw Normal View History

2021-05-28 16:15:17 +00:00
// Copyright 2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
// State
export type GlobalModalsStateType = {
2021-07-19 19:26:06 +00:00
readonly isProfileEditorVisible: boolean;
readonly profileEditorHasError: boolean;
2021-05-28 16:15:17 +00:00
};
// Actions
2021-07-19 19:26:06 +00:00
const TOGGLE_PROFILE_EDITOR = 'globalModals/TOGGLE_PROFILE_EDITOR';
export const TOGGLE_PROFILE_EDITOR_ERROR =
'globalModals/TOGGLE_PROFILE_EDITOR_ERROR';
2021-05-28 16:15:17 +00:00
2021-07-19 19:26:06 +00:00
type ToggleProfileEditorActionType = {
type: typeof TOGGLE_PROFILE_EDITOR;
};
export type ToggleProfileEditorErrorActionType = {
type: typeof TOGGLE_PROFILE_EDITOR_ERROR;
};
export type GlobalModalsActionType =
| ToggleProfileEditorActionType
| ToggleProfileEditorErrorActionType;
2021-05-28 16:15:17 +00:00
// Action Creators
export const actions = {
2021-07-19 19:26:06 +00:00
toggleProfileEditor,
toggleProfileEditorHasError,
2021-05-28 16:15:17 +00:00
};
2021-07-19 19:26:06 +00:00
function toggleProfileEditor(): ToggleProfileEditorActionType {
return { type: TOGGLE_PROFILE_EDITOR };
}
function toggleProfileEditorHasError(): ToggleProfileEditorErrorActionType {
return { type: TOGGLE_PROFILE_EDITOR_ERROR };
}
2021-05-28 16:15:17 +00:00
// Reducer
export function getEmptyState(): GlobalModalsStateType {
return {
2021-07-19 19:26:06 +00:00
isProfileEditorVisible: false,
profileEditorHasError: false,
2021-05-28 16:15:17 +00:00
};
}
export function reducer(
state: Readonly<GlobalModalsStateType> = getEmptyState(),
action: Readonly<GlobalModalsActionType>
): GlobalModalsStateType {
2021-07-19 19:26:06 +00:00
if (action.type === TOGGLE_PROFILE_EDITOR) {
return {
...state,
isProfileEditorVisible: !state.isProfileEditorVisible,
};
}
if (action.type === TOGGLE_PROFILE_EDITOR_ERROR) {
return {
...state,
profileEditorHasError: !state.profileEditorHasError,
};
}
2021-05-28 16:15:17 +00:00
return state;
}