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

93 lines
2.2 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 = {
readonly isChatColorEditorVisible: boolean;
2021-07-19 19:26:06 +00:00
readonly isProfileEditorVisible: boolean;
readonly profileEditorHasError: boolean;
2021-05-28 16:15:17 +00:00
};
// Actions
const TOGGLE_CHAT_COLOR_EDITOR = 'globalModals/TOGGLE_CHAT_COLOR_EDITOR';
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
type ToggleChatColorEditorActionType = {
type: typeof TOGGLE_CHAT_COLOR_EDITOR;
};
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 =
| ToggleChatColorEditorActionType
| ToggleProfileEditorActionType
| ToggleProfileEditorErrorActionType;
2021-05-28 16:15:17 +00:00
// Action Creators
export const actions = {
toggleChatColorEditor,
2021-07-19 19:26:06 +00:00
toggleProfileEditor,
toggleProfileEditorHasError,
2021-05-28 16:15:17 +00:00
};
function toggleChatColorEditor(): ToggleChatColorEditorActionType {
return { type: TOGGLE_CHAT_COLOR_EDITOR };
}
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 {
isChatColorEditorVisible: false,
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 {
if (action.type === TOGGLE_CHAT_COLOR_EDITOR) {
return {
...state,
isChatColorEditorVisible: !state.isChatColorEditorVisible,
};
}
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;
}