Moves sendMessage and friends to redux
This commit is contained in:
parent
7ea38bb1a9
commit
2378776e1b
27 changed files with 517 additions and 537 deletions
|
@ -35,7 +35,9 @@ const useProps = (overrideProps: Partial<Props> = {}): Props => ({
|
|||
addAttachment: action('addAttachment'),
|
||||
conversationId: '123',
|
||||
i18n,
|
||||
onSendMessage: action('onSendMessage'),
|
||||
isDisabled: false,
|
||||
messageCompositionId: '456',
|
||||
sendMultiMediaMessage: action('sendMultiMediaMessage'),
|
||||
processAttachments: action('processAttachments'),
|
||||
removeAttachment: action('removeAttachment'),
|
||||
theme: React.useContext(StorybookThemeContext),
|
||||
|
@ -89,7 +91,7 @@ const useProps = (overrideProps: Partial<Props> = {}): Props => ({
|
|||
recentStickers: [],
|
||||
clearInstalledStickerPack: action('clearInstalledStickerPack'),
|
||||
onClickAddPack: action('onClickAddPack'),
|
||||
onPickSticker: action('onPickSticker'),
|
||||
sendStickerMessage: action('sendStickerMessage'),
|
||||
clearShowIntroduction: action('clearShowIntroduction'),
|
||||
showPickerHint: false,
|
||||
clearShowPickerHint: action('clearShowPickerHint'),
|
||||
|
|
|
@ -63,8 +63,6 @@ export type CompositionAPIType =
|
|||
| {
|
||||
focusInput: () => void;
|
||||
isDirty: () => boolean;
|
||||
setDisabled: (disabled: boolean) => void;
|
||||
reset: InputApi['reset'];
|
||||
resetEmojiResults: InputApi['resetEmojiResults'];
|
||||
}
|
||||
| undefined;
|
||||
|
@ -94,11 +92,13 @@ export type OwnProps = Readonly<{
|
|||
groupVersion?: 1 | 2;
|
||||
i18n: LocalizerType;
|
||||
imageToBlurHash: typeof imageToBlurHash;
|
||||
isDisabled: boolean;
|
||||
isFetchingUUID?: boolean;
|
||||
isGroupV1AndDisabled?: boolean;
|
||||
isMissingMandatoryProfileSharing?: boolean;
|
||||
isSignalConversation?: boolean;
|
||||
recordingState: RecordingState;
|
||||
messageCompositionId: string;
|
||||
isSMSOnly?: boolean;
|
||||
left?: boolean;
|
||||
linkPreviewLoading: boolean;
|
||||
|
@ -112,13 +112,20 @@ export type OwnProps = Readonly<{
|
|||
files: ReadonlyArray<File>;
|
||||
}) => unknown;
|
||||
onSelectMediaQuality(isHQ: boolean): unknown;
|
||||
onSendMessage(options: {
|
||||
draftAttachments?: ReadonlyArray<AttachmentDraftType>;
|
||||
mentions?: DraftBodyRangesType;
|
||||
message?: string;
|
||||
timestamp?: number;
|
||||
voiceNoteAttachment?: InMemoryAttachmentDraftType;
|
||||
}): unknown;
|
||||
sendStickerMessage(
|
||||
id: string,
|
||||
opts: { packId: string; stickerId: number }
|
||||
): unknown;
|
||||
sendMultiMediaMessage(
|
||||
conversationId: string,
|
||||
options: {
|
||||
draftAttachments?: ReadonlyArray<AttachmentDraftType>;
|
||||
mentions?: DraftBodyRangesType;
|
||||
message?: string;
|
||||
timestamp?: number;
|
||||
voiceNoteAttachment?: InMemoryAttachmentDraftType;
|
||||
}
|
||||
): unknown;
|
||||
openConversation(conversationId: string): unknown;
|
||||
quotedMessageProps?: Omit<
|
||||
QuoteProps,
|
||||
|
@ -156,7 +163,6 @@ export type Props = Pick<
|
|||
| 'recentStickers'
|
||||
| 'clearInstalledStickerPack'
|
||||
| 'onClickAddPack'
|
||||
| 'onPickSticker'
|
||||
| 'clearShowIntroduction'
|
||||
| 'showPickerHint'
|
||||
| 'clearShowPickerHint'
|
||||
|
@ -171,12 +177,14 @@ export function CompositionArea({
|
|||
addAttachment,
|
||||
conversationId,
|
||||
i18n,
|
||||
onSendMessage,
|
||||
imageToBlurHash,
|
||||
isDisabled,
|
||||
isSignalConversation,
|
||||
processAttachments,
|
||||
removeAttachment,
|
||||
messageCompositionId,
|
||||
sendMultiMediaMessage,
|
||||
theme,
|
||||
isSignalConversation,
|
||||
|
||||
// AttachmentList
|
||||
draftAttachments,
|
||||
|
@ -223,7 +231,7 @@ export function CompositionArea({
|
|||
recentStickers,
|
||||
clearInstalledStickerPack,
|
||||
onClickAddPack,
|
||||
onPickSticker,
|
||||
sendStickerMessage,
|
||||
clearShowIntroduction,
|
||||
showPickerHint,
|
||||
clearShowPickerHint,
|
||||
|
@ -255,7 +263,6 @@ export function CompositionArea({
|
|||
isSMSOnly,
|
||||
isFetchingUUID,
|
||||
}: Props): JSX.Element {
|
||||
const [disabled, setDisabled] = useState(false);
|
||||
const [dirty, setDirty] = useState(false);
|
||||
const [large, setLarge] = useState(false);
|
||||
const [attachmentToEdit, setAttachmentToEdit] = useState<
|
||||
|
@ -275,7 +282,7 @@ export function CompositionArea({
|
|||
const handleSubmit = useCallback(
|
||||
(message: string, mentions: DraftBodyRangesType, timestamp: number) => {
|
||||
emojiButtonRef.current?.close();
|
||||
onSendMessage({
|
||||
sendMultiMediaMessage(conversationId, {
|
||||
draftAttachments,
|
||||
mentions,
|
||||
message,
|
||||
|
@ -283,7 +290,7 @@ export function CompositionArea({
|
|||
});
|
||||
setLarge(false);
|
||||
},
|
||||
[draftAttachments, onSendMessage, setLarge]
|
||||
[conversationId, draftAttachments, sendMultiMediaMessage, setLarge]
|
||||
);
|
||||
|
||||
const launchAttachmentPicker = useCallback(() => {
|
||||
|
@ -327,12 +334,6 @@ export function CompositionArea({
|
|||
compositionApi.current = {
|
||||
isDirty: () => dirty,
|
||||
focusInput,
|
||||
setDisabled,
|
||||
reset: () => {
|
||||
if (inputApiRef.current) {
|
||||
inputApiRef.current.reset();
|
||||
}
|
||||
},
|
||||
resetEmojiResults: () => {
|
||||
if (inputApiRef.current) {
|
||||
inputApiRef.current.resetEmojiResults();
|
||||
|
@ -341,6 +342,14 @@ export function CompositionArea({
|
|||
};
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
if (!inputApiRef.current) {
|
||||
return;
|
||||
}
|
||||
|
||||
inputApiRef.current.reset();
|
||||
}, [messageCompositionId]);
|
||||
|
||||
const insertEmoji = useCallback(
|
||||
(e: EmojiPickDataType) => {
|
||||
if (inputApiRef.current) {
|
||||
|
@ -400,7 +409,7 @@ export function CompositionArea({
|
|||
voiceNoteAttachment: InMemoryAttachmentDraftType
|
||||
) => {
|
||||
emojiButtonRef.current?.close();
|
||||
onSendMessage({ voiceNoteAttachment });
|
||||
sendMultiMediaMessage(conversationId, { voiceNoteAttachment });
|
||||
}}
|
||||
startRecording={startRecording}
|
||||
/>
|
||||
|
@ -447,7 +456,9 @@ export function CompositionArea({
|
|||
recentStickers={recentStickers}
|
||||
clearInstalledStickerPack={clearInstalledStickerPack}
|
||||
onClickAddPack={onClickAddPack}
|
||||
onPickSticker={onPickSticker}
|
||||
onPickSticker={(packId, stickerId) =>
|
||||
sendStickerMessage(conversationId, { packId, stickerId })
|
||||
}
|
||||
clearShowIntroduction={clearShowIntroduction}
|
||||
showPickerHint={showPickerHint}
|
||||
clearShowPickerHint={clearShowPickerHint}
|
||||
|
@ -690,7 +701,7 @@ export function CompositionArea({
|
|||
>
|
||||
<CompositionInput
|
||||
clearQuotedMessage={clearQuotedMessage}
|
||||
disabled={disabled}
|
||||
disabled={isDisabled}
|
||||
draftBodyRanges={draftBodyRanges}
|
||||
draftText={draftText}
|
||||
getPreferredBadge={getPreferredBadge}
|
||||
|
|
|
@ -1,28 +0,0 @@
|
|||
// Copyright 2021 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import React from 'react';
|
||||
import { action } from '@storybook/addon-actions';
|
||||
import { ToastBlocked } from './ToastBlocked';
|
||||
|
||||
import { setupI18n } from '../util/setupI18n';
|
||||
import enMessages from '../../_locales/en/messages.json';
|
||||
|
||||
const i18n = setupI18n('en', enMessages);
|
||||
|
||||
const defaultProps = {
|
||||
i18n,
|
||||
onClose: action('onClose'),
|
||||
};
|
||||
|
||||
export default {
|
||||
title: 'Components/ToastBlocked',
|
||||
};
|
||||
|
||||
export const _ToastBlocked = (): JSX.Element => (
|
||||
<ToastBlocked {...defaultProps} />
|
||||
);
|
||||
|
||||
_ToastBlocked.story = {
|
||||
name: 'ToastBlocked',
|
||||
};
|
|
@ -1,15 +0,0 @@
|
|||
// Copyright 2021 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import React from 'react';
|
||||
import type { LocalizerType } from '../types/Util';
|
||||
import { Toast } from './Toast';
|
||||
|
||||
type PropsType = {
|
||||
i18n: LocalizerType;
|
||||
onClose: () => unknown;
|
||||
};
|
||||
|
||||
export function ToastBlocked({ i18n, onClose }: PropsType): JSX.Element {
|
||||
return <Toast onClose={onClose}>{i18n('unblockToSend')}</Toast>;
|
||||
}
|
|
@ -1,28 +0,0 @@
|
|||
// Copyright 2021 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import React from 'react';
|
||||
import { action } from '@storybook/addon-actions';
|
||||
import { ToastBlockedGroup } from './ToastBlockedGroup';
|
||||
|
||||
import { setupI18n } from '../util/setupI18n';
|
||||
import enMessages from '../../_locales/en/messages.json';
|
||||
|
||||
const i18n = setupI18n('en', enMessages);
|
||||
|
||||
const defaultProps = {
|
||||
i18n,
|
||||
onClose: action('onClose'),
|
||||
};
|
||||
|
||||
export default {
|
||||
title: 'Components/ToastBlockedGroup',
|
||||
};
|
||||
|
||||
export const _ToastBlockedGroup = (): JSX.Element => (
|
||||
<ToastBlockedGroup {...defaultProps} />
|
||||
);
|
||||
|
||||
_ToastBlockedGroup.story = {
|
||||
name: 'ToastBlockedGroup',
|
||||
};
|
|
@ -1,15 +0,0 @@
|
|||
// Copyright 2021 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import React from 'react';
|
||||
import type { LocalizerType } from '../types/Util';
|
||||
import { Toast } from './Toast';
|
||||
|
||||
type PropsType = {
|
||||
i18n: LocalizerType;
|
||||
onClose: () => unknown;
|
||||
};
|
||||
|
||||
export function ToastBlockedGroup({ i18n, onClose }: PropsType): JSX.Element {
|
||||
return <Toast onClose={onClose}>{i18n('unblockGroupToSend')}</Toast>;
|
||||
}
|
|
@ -1,28 +0,0 @@
|
|||
// Copyright 2021 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import React from 'react';
|
||||
import { action } from '@storybook/addon-actions';
|
||||
import { ToastExpired } from './ToastExpired';
|
||||
|
||||
import { setupI18n } from '../util/setupI18n';
|
||||
import enMessages from '../../_locales/en/messages.json';
|
||||
|
||||
const i18n = setupI18n('en', enMessages);
|
||||
|
||||
const defaultProps = {
|
||||
i18n,
|
||||
onClose: action('onClose'),
|
||||
};
|
||||
|
||||
export default {
|
||||
title: 'Components/ToastExpired',
|
||||
};
|
||||
|
||||
export const _ToastExpired = (): JSX.Element => (
|
||||
<ToastExpired {...defaultProps} />
|
||||
);
|
||||
|
||||
_ToastExpired.story = {
|
||||
name: 'ToastExpired',
|
||||
};
|
|
@ -1,15 +0,0 @@
|
|||
// Copyright 2021 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import React from 'react';
|
||||
import type { LocalizerType } from '../types/Util';
|
||||
import { Toast } from './Toast';
|
||||
|
||||
type PropsType = {
|
||||
i18n: LocalizerType;
|
||||
onClose: () => unknown;
|
||||
};
|
||||
|
||||
export function ToastExpired({ i18n, onClose }: PropsType): JSX.Element {
|
||||
return <Toast onClose={onClose}>{i18n('expiredWarning')}</Toast>;
|
||||
}
|
|
@ -1,28 +0,0 @@
|
|||
// Copyright 2021 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import React from 'react';
|
||||
import { action } from '@storybook/addon-actions';
|
||||
import { ToastInvalidConversation } from './ToastInvalidConversation';
|
||||
|
||||
import { setupI18n } from '../util/setupI18n';
|
||||
import enMessages from '../../_locales/en/messages.json';
|
||||
|
||||
const i18n = setupI18n('en', enMessages);
|
||||
|
||||
const defaultProps = {
|
||||
i18n,
|
||||
onClose: action('onClose'),
|
||||
};
|
||||
|
||||
export default {
|
||||
title: 'Components/ToastInvalidConversation',
|
||||
};
|
||||
|
||||
export const _ToastInvalidConversation = (): JSX.Element => (
|
||||
<ToastInvalidConversation {...defaultProps} />
|
||||
);
|
||||
|
||||
_ToastInvalidConversation.story = {
|
||||
name: 'ToastInvalidConversation',
|
||||
};
|
|
@ -1,18 +0,0 @@
|
|||
// Copyright 2021 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import React from 'react';
|
||||
import type { LocalizerType } from '../types/Util';
|
||||
import { Toast } from './Toast';
|
||||
|
||||
type PropsType = {
|
||||
i18n: LocalizerType;
|
||||
onClose: () => unknown;
|
||||
};
|
||||
|
||||
export function ToastInvalidConversation({
|
||||
i18n,
|
||||
onClose,
|
||||
}: PropsType): JSX.Element {
|
||||
return <Toast onClose={onClose}>{i18n('invalidConversation')}</Toast>;
|
||||
}
|
|
@ -1,28 +0,0 @@
|
|||
// Copyright 2021 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import React from 'react';
|
||||
import { action } from '@storybook/addon-actions';
|
||||
import { ToastLeftGroup } from './ToastLeftGroup';
|
||||
|
||||
import { setupI18n } from '../util/setupI18n';
|
||||
import enMessages from '../../_locales/en/messages.json';
|
||||
|
||||
const i18n = setupI18n('en', enMessages);
|
||||
|
||||
const defaultProps = {
|
||||
i18n,
|
||||
onClose: action('onClose'),
|
||||
};
|
||||
|
||||
export default {
|
||||
title: 'Components/ToastLeftGroup',
|
||||
};
|
||||
|
||||
export const _ToastLeftGroup = (): JSX.Element => (
|
||||
<ToastLeftGroup {...defaultProps} />
|
||||
);
|
||||
|
||||
_ToastLeftGroup.story = {
|
||||
name: 'ToastLeftGroup',
|
||||
};
|
|
@ -1,15 +0,0 @@
|
|||
// Copyright 2021 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import React from 'react';
|
||||
import type { LocalizerType } from '../types/Util';
|
||||
import { Toast } from './Toast';
|
||||
|
||||
type PropsType = {
|
||||
i18n: LocalizerType;
|
||||
onClose: () => unknown;
|
||||
};
|
||||
|
||||
export function ToastLeftGroup({ i18n, onClose }: PropsType): JSX.Element {
|
||||
return <Toast onClose={onClose}>{i18n('youLeftTheGroup')}</Toast>;
|
||||
}
|
|
@ -49,6 +49,20 @@ AddingUserToGroup.args = {
|
|||
},
|
||||
};
|
||||
|
||||
export const Blocked = Template.bind({});
|
||||
Blocked.args = {
|
||||
toast: {
|
||||
toastType: ToastType.Blocked,
|
||||
},
|
||||
};
|
||||
|
||||
export const BlockedGroup = Template.bind({});
|
||||
BlockedGroup.args = {
|
||||
toast: {
|
||||
toastType: ToastType.BlockedGroup,
|
||||
},
|
||||
};
|
||||
|
||||
export const CannotMixMultiAndNonMultiAttachments = Template.bind({});
|
||||
CannotMixMultiAndNonMultiAttachments.args = {
|
||||
toast: {
|
||||
|
@ -98,6 +112,13 @@ Error.args = {
|
|||
},
|
||||
};
|
||||
|
||||
export const Expired = Template.bind({});
|
||||
Expired.args = {
|
||||
toast: {
|
||||
toastType: ToastType.Expired,
|
||||
},
|
||||
};
|
||||
|
||||
export const FailedToDeleteUsername = Template.bind({});
|
||||
FailedToDeleteUsername.args = {
|
||||
toast: {
|
||||
|
@ -116,6 +137,20 @@ FileSize.args = {
|
|||
},
|
||||
};
|
||||
|
||||
export const InvalidConversation = Template.bind({});
|
||||
InvalidConversation.args = {
|
||||
toast: {
|
||||
toastType: ToastType.InvalidConversation,
|
||||
},
|
||||
};
|
||||
|
||||
export const LeftGroup = Template.bind({});
|
||||
LeftGroup.args = {
|
||||
toast: {
|
||||
toastType: ToastType.LeftGroup,
|
||||
},
|
||||
};
|
||||
|
||||
export const MaxAttachments = Template.bind({});
|
||||
MaxAttachments.args = {
|
||||
toast: {
|
||||
|
|
|
@ -42,6 +42,14 @@ export function ToastManager({
|
|||
);
|
||||
}
|
||||
|
||||
if (toastType === ToastType.Blocked) {
|
||||
return <Toast onClose={hideToast}>{i18n('unblockToSend')}</Toast>;
|
||||
}
|
||||
|
||||
if (toastType === ToastType.BlockedGroup) {
|
||||
return <Toast onClose={hideToast}>{i18n('unblockGroupToSend')}</Toast>;
|
||||
}
|
||||
|
||||
if (toastType === ToastType.CannotMixMultiAndNonMultiAttachments) {
|
||||
return (
|
||||
<Toast onClose={hideToast}>
|
||||
|
@ -97,6 +105,10 @@ export function ToastManager({
|
|||
);
|
||||
}
|
||||
|
||||
if (toastType === ToastType.Expired) {
|
||||
return <Toast onClose={hideToast}>{i18n('expiredWarning')}</Toast>;
|
||||
}
|
||||
|
||||
if (toastType === ToastType.FailedToDeleteUsername) {
|
||||
return (
|
||||
<Toast onClose={hideToast}>
|
||||
|
@ -113,6 +125,14 @@ export function ToastManager({
|
|||
);
|
||||
}
|
||||
|
||||
if (toastType === ToastType.InvalidConversation) {
|
||||
return <Toast onClose={hideToast}>{i18n('invalidConversation')}</Toast>;
|
||||
}
|
||||
|
||||
if (toastType === ToastType.LeftGroup) {
|
||||
return <Toast onClose={hideToast}>{i18n('youLeftTheGroup')}</Toast>;
|
||||
}
|
||||
|
||||
if (toastType === ToastType.MaxAttachments) {
|
||||
return <Toast onClose={hideToast}>{i18n('maximumAttachments')}</Toast>;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue