conversation_view: Move the last of the small functions to redux

This commit is contained in:
Scott Nonnenberg 2022-12-20 19:25:10 -08:00 committed by GitHub
parent 86e92dda51
commit 1a68c3db62
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
59 changed files with 782 additions and 944 deletions

View file

@ -5,7 +5,6 @@ import React from 'react';
import type { LocalizerType, ReplacementValuesType } from '../types/Util';
import { SECOND } from '../util/durations';
import { Toast } from './Toast';
import { ToastMessageBodyTooLong } from './ToastMessageBodyTooLong';
import { missingCaseError } from '../util/missingCaseError';
import { ToastType } from '../types/Toast';
@ -13,6 +12,7 @@ export type PropsType = {
hideToast: () => unknown;
i18n: LocalizerType;
openFileInFolder: (target: string) => unknown;
onUndoArchive: (conversaetionId: string) => unknown;
toast?: {
toastType: ToastType;
parameters?: ReplacementValuesType;
@ -25,6 +25,7 @@ export function ToastManager({
hideToast,
i18n,
openFileInFolder,
onUndoArchive,
toast,
}: PropsType): JSX.Element | null {
if (toast === undefined) {
@ -84,6 +85,36 @@ export function ToastManager({
);
}
if (toastType === ToastType.ConversationArchived) {
return (
<Toast
onClose={hideToast}
toastAction={{
label: i18n('conversationArchivedUndo'),
onClick: () => {
if (toast.parameters && 'conversationId' in toast.parameters) {
onUndoArchive(String(toast.parameters.conversationId));
}
},
}}
>
{i18n('conversationArchived')}
</Toast>
);
}
if (toastType === ToastType.ConversationMarkedUnread) {
return (
<Toast onClose={hideToast}>{i18n('conversationMarkedUnread')}</Toast>
);
}
if (toastType === ToastType.ConversationUnarchived) {
return (
<Toast onClose={hideToast}>{i18n('conversationReturnedToInbox')}</Toast>
);
}
if (toastType === ToastType.CopiedUsername) {
return (
<Toast onClose={hideToast} timeout={3 * SECOND}>
@ -174,15 +205,11 @@ export function ToastManager({
}
if (toastType === ToastType.MessageBodyTooLong) {
return <ToastMessageBodyTooLong i18n={i18n} onClose={hideToast} />;
return <Toast onClose={hideToast}>{i18n('messageBodyTooLong')}</Toast>;
}
if (toastType === ToastType.ReportedSpamAndBlocked) {
return (
<Toast onClose={hideToast}>
{i18n('MessageRequests--block-and-report-spam-success-toast')}
</Toast>
);
if (toastType === ToastType.OriginalMessageNotFound) {
return <Toast onClose={hideToast}>{i18n('originalMessageNotFound')}</Toast>;
}
if (toastType === ToastType.PinnedConversationsFull) {
@ -193,6 +220,14 @@ export function ToastManager({
return <Toast onClose={hideToast}>{i18n('Reactions--error')}</Toast>;
}
if (toastType === ToastType.ReportedSpamAndBlocked) {
return (
<Toast onClose={hideToast}>
{i18n('MessageRequests--block-and-report-spam-success-toast')}
</Toast>
);
}
if (toastType === ToastType.StoryMuted) {
return (
<Toast onClose={hideToast} timeout={SHORT_TIMEOUT}>