2024-01-29 20:09:54 +00:00
|
|
|
// Copyright 2024 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2024-03-13 20:44:13 +00:00
|
|
|
import React, { memo } from 'react';
|
2024-01-29 20:09:54 +00:00
|
|
|
import { useSelector } from 'react-redux';
|
|
|
|
import type { AnyActionableMegaphone } from '../../types/Megaphone';
|
|
|
|
import { MegaphoneType } from '../../types/Megaphone';
|
|
|
|
import { UsernameOnboardingState } from '../../types/globalModals';
|
|
|
|
import OS from '../../util/os/osMain';
|
|
|
|
import { drop } from '../../util/drop';
|
|
|
|
import { getIntl } from '../selectors/user';
|
|
|
|
import {
|
|
|
|
getGlobalModalsState,
|
|
|
|
isShowingAnyModal as getIsShowingAnyModal,
|
|
|
|
} from '../selectors/globalModals';
|
|
|
|
import { hasSelectedStoryData } from '../selectors/stories';
|
|
|
|
import { shouldShowLightbox } from '../selectors/lightbox';
|
|
|
|
import { isInFullScreenCall as getIsInFullScreenCall } from '../selectors/calling';
|
|
|
|
import { getSelectedNavTab } from '../selectors/nav';
|
2024-03-13 20:44:13 +00:00
|
|
|
import { getMe, getSelectedConversationId } from '../selectors/conversations';
|
2024-01-29 20:09:54 +00:00
|
|
|
import { useConversationsActions } from '../ducks/conversations';
|
|
|
|
import { useToastActions } from '../ducks/toast';
|
|
|
|
import { useGlobalModalActions } from '../ducks/globalModals';
|
|
|
|
import { NavTab } from '../ducks/nav';
|
2024-02-08 00:34:31 +00:00
|
|
|
import { getHasCompletedUsernameOnboarding } from '../selectors/items';
|
2024-01-29 20:09:54 +00:00
|
|
|
import { ToastManager } from '../../components/ToastManager';
|
|
|
|
import type { WidthBreakpoint } from '../../components/_util';
|
2024-03-13 20:44:13 +00:00
|
|
|
import { getToast } from '../selectors/toast';
|
2024-01-29 20:09:54 +00:00
|
|
|
|
|
|
|
export type SmartPropsType = Readonly<{
|
|
|
|
disableMegaphone?: boolean;
|
|
|
|
containerWidthBreakpoint: WidthBreakpoint;
|
|
|
|
}>;
|
|
|
|
|
2024-03-13 20:44:13 +00:00
|
|
|
export const SmartToastManager = memo(function SmartToastManager({
|
2024-01-29 20:09:54 +00:00
|
|
|
disableMegaphone = false,
|
|
|
|
containerWidthBreakpoint,
|
2024-03-13 20:44:13 +00:00
|
|
|
}: SmartPropsType) {
|
2024-01-29 20:09:54 +00:00
|
|
|
const i18n = useSelector(getIntl);
|
|
|
|
const hasCompletedUsernameOnboarding = useSelector(
|
|
|
|
getHasCompletedUsernameOnboarding
|
|
|
|
);
|
2024-03-13 20:44:13 +00:00
|
|
|
const toast = useSelector(getToast);
|
2024-01-29 20:09:54 +00:00
|
|
|
const globalModals = useSelector(getGlobalModalsState);
|
|
|
|
const isShowingAnyModal = useSelector(getIsShowingAnyModal);
|
|
|
|
const isShowingStory = useSelector(hasSelectedStoryData);
|
|
|
|
const isShowingLightbox = useSelector(shouldShowLightbox);
|
|
|
|
const isInFullScreenCall = useSelector(getIsInFullScreenCall);
|
2024-01-30 19:32:38 +00:00
|
|
|
const { username } = useSelector(getMe);
|
2024-01-29 20:09:54 +00:00
|
|
|
const selectedNavTab = useSelector(getSelectedNavTab);
|
2024-03-13 20:44:13 +00:00
|
|
|
const selectedConversationId = useSelector(getSelectedConversationId);
|
2024-01-29 20:09:54 +00:00
|
|
|
|
|
|
|
const { onUndoArchive } = useConversationsActions();
|
|
|
|
const { openFileInFolder, hideToast } = useToastActions();
|
|
|
|
const { toggleUsernameOnboarding } = useGlobalModalActions();
|
|
|
|
|
|
|
|
let megaphone: AnyActionableMegaphone | undefined;
|
|
|
|
|
|
|
|
if (
|
|
|
|
!hasCompletedUsernameOnboarding &&
|
2024-01-30 19:32:38 +00:00
|
|
|
!username &&
|
2024-01-29 20:09:54 +00:00
|
|
|
globalModals.usernameOnboardingState === UsernameOnboardingState.NeverShown
|
|
|
|
) {
|
|
|
|
megaphone = {
|
|
|
|
type: MegaphoneType.UsernameOnboarding,
|
|
|
|
onLearnMore: toggleUsernameOnboarding,
|
|
|
|
onDismiss: () => {
|
|
|
|
drop(window.storage.put('hasCompletedUsernameOnboarding', true));
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
const centerToast =
|
|
|
|
isShowingAnyModal ||
|
|
|
|
isShowingStory ||
|
|
|
|
isShowingLightbox ||
|
|
|
|
isInFullScreenCall;
|
|
|
|
|
|
|
|
const isCompositionAreaVisible =
|
|
|
|
selectedNavTab === NavTab.Chats && Boolean(selectedConversationId);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<ToastManager
|
|
|
|
i18n={i18n}
|
|
|
|
OS={OS.getName()}
|
|
|
|
toast={toast}
|
|
|
|
megaphone={disableMegaphone ? undefined : megaphone}
|
|
|
|
onShowDebugLog={() => window.IPC.showDebugLog()}
|
|
|
|
onUndoArchive={onUndoArchive}
|
|
|
|
openFileInFolder={openFileInFolder}
|
|
|
|
hideToast={hideToast}
|
|
|
|
centerToast={centerToast}
|
|
|
|
containerWidthBreakpoint={containerWidthBreakpoint}
|
|
|
|
isCompositionAreaVisible={isCompositionAreaVisible}
|
|
|
|
/>
|
|
|
|
);
|
2024-03-13 20:44:13 +00:00
|
|
|
});
|