Refactor smart components
Co-authored-by: Fedor Indutny <79877362+indutny-signal@users.noreply.github.com>
This commit is contained in:
parent
05c09ef769
commit
27b55e472d
109 changed files with 3583 additions and 2629 deletions
|
@ -1,7 +1,7 @@
|
|||
// Copyright 2022 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import React, { useCallback } from 'react';
|
||||
import React, { memo, useCallback } from 'react';
|
||||
import { useSelector } from 'react-redux';
|
||||
import { CompositionRecording } from '../../components/CompositionRecording';
|
||||
import { mapDispatchToProps } from '../actions';
|
||||
|
@ -15,49 +15,53 @@ export type SmartCompositionRecordingProps = {
|
|||
onBeforeSend: () => void;
|
||||
};
|
||||
|
||||
export function SmartCompositionRecording({
|
||||
onBeforeSend,
|
||||
}: SmartCompositionRecordingProps): JSX.Element | null {
|
||||
const i18n = useSelector(getIntl);
|
||||
const selectedConversationId = useSelector(getSelectedConversationId);
|
||||
const { cancelRecording, completeRecording } = useAudioRecorderActions();
|
||||
|
||||
const { sendMultiMediaMessage } = useComposerActions();
|
||||
const { hideToast, showToast } = useToastActions();
|
||||
|
||||
const handleCancel = useCallback(() => {
|
||||
cancelRecording();
|
||||
}, [cancelRecording]);
|
||||
|
||||
const handleSend = useCallback(() => {
|
||||
if (selectedConversationId) {
|
||||
completeRecording(selectedConversationId, voiceNoteAttachment => {
|
||||
onBeforeSend();
|
||||
sendMultiMediaMessage(selectedConversationId, { voiceNoteAttachment });
|
||||
});
|
||||
}
|
||||
}, [
|
||||
selectedConversationId,
|
||||
completeRecording,
|
||||
export const SmartCompositionRecording = memo(
|
||||
function SmartCompositionRecording({
|
||||
onBeforeSend,
|
||||
sendMultiMediaMessage,
|
||||
]);
|
||||
}: SmartCompositionRecordingProps) {
|
||||
const i18n = useSelector(getIntl);
|
||||
const selectedConversationId = useSelector(getSelectedConversationId);
|
||||
const { cancelRecording, completeRecording } = useAudioRecorderActions();
|
||||
|
||||
if (!selectedConversationId) {
|
||||
return null;
|
||||
const { sendMultiMediaMessage } = useComposerActions();
|
||||
const { hideToast, showToast } = useToastActions();
|
||||
|
||||
const handleCancel = useCallback(() => {
|
||||
cancelRecording();
|
||||
}, [cancelRecording]);
|
||||
|
||||
const handleSend = useCallback(() => {
|
||||
if (selectedConversationId) {
|
||||
completeRecording(selectedConversationId, voiceNoteAttachment => {
|
||||
onBeforeSend();
|
||||
sendMultiMediaMessage(selectedConversationId, {
|
||||
voiceNoteAttachment,
|
||||
});
|
||||
});
|
||||
}
|
||||
}, [
|
||||
selectedConversationId,
|
||||
completeRecording,
|
||||
onBeforeSend,
|
||||
sendMultiMediaMessage,
|
||||
]);
|
||||
|
||||
if (!selectedConversationId) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<CompositionRecording
|
||||
i18n={i18n}
|
||||
conversationId={selectedConversationId}
|
||||
onCancel={handleCancel}
|
||||
onSend={handleSend}
|
||||
errorRecording={mapDispatchToProps.errorRecording}
|
||||
addAttachment={mapDispatchToProps.addAttachment}
|
||||
completeRecording={mapDispatchToProps.completeRecording}
|
||||
showToast={showToast}
|
||||
hideToast={hideToast}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<CompositionRecording
|
||||
i18n={i18n}
|
||||
conversationId={selectedConversationId}
|
||||
onCancel={handleCancel}
|
||||
onSend={handleSend}
|
||||
errorRecording={mapDispatchToProps.errorRecording}
|
||||
addAttachment={mapDispatchToProps.addAttachment}
|
||||
completeRecording={mapDispatchToProps.completeRecording}
|
||||
showToast={showToast}
|
||||
hideToast={hideToast}
|
||||
/>
|
||||
);
|
||||
}
|
||||
);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue