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