Skip to content

Commit 5a7a3a5

Browse files
authored
fix: Clean up UI of voice message in mobile mode (#488)
Fix bugs * Call `VoiceRecorder.cancel` when closing the VoiceMessageInputWrapper * solved issue: VoicePlayer doesn't play after VoiceMessageInputWrapper is closed this is because VoicePlayer doesn't allow to play during recording, so it should specify the recording is done Fix styles * Reduce the maximum width of a message because of overflow * Fix the text-overflow on the channel preview * Remove the div tag containing the string to apply the ellipsis on the channel preview Chore * Fix typo `isSubmited` to `isSubmitted` * Leave comments and Optimize the VoiceMessageInputWrapper * Add a logger to find out the path through which AudioFile is obtained
1 parent 731cef6 commit 5a7a3a5

File tree

6 files changed

+21
-13
lines changed

6 files changed

+21
-13
lines changed

src/hooks/VoicePlayer/index.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,15 @@ export const VoicePlayerProvider = ({
9393
voicePlayerRoot.removeChild(voicePlayerAudioElement);
9494
}
9595

96+
logger.info('VoicePlayer: Start getting audio file.');
9697
new Promise((resolve) => {
9798
if (audioFile) {
9899
resolve(audioFile);
100+
logger.info('VoicePlayer: Use the audioFile instance.');
99101
}
100102
if (audioStorage?.[groupKey]?.audioFile) {
101-
resolve(audioStorage[groupKey].audioFile)
103+
resolve(audioStorage[groupKey].audioFile);
104+
logger.info('VoicePlayer: Get from the audioStorage.');
102105
}
103106
voicePlayerDispatcher({
104107
type: INITIALIZE_AUDIO_UNIT,
@@ -112,6 +115,7 @@ export const VoicePlayerProvider = ({
112115
type: VOICE_MESSAGE_MIME_TYPE,
113116
});
114117
resolve(audioFile);
118+
logger.info('VoicePlayer: Get the audioFile from URL.');
115119
});
116120
}).then((audioFile: File) => {
117121
logger.info('VoicePlayer: Succeeded getting audio file.', audioFile);

src/smart-components/Channel/components/MessageInput/VoiceMessageInputWrapper.tsx

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useEffect, useState } from 'react';
1+
import React, { useEffect, useRef, useState } from 'react';
22
import { GroupChannel } from '@sendbird/chat/groupChannel';
33
import './voice-message-wrapper.scss';
44

@@ -27,10 +27,10 @@ export const VoiceMessageInputWrapper = ({
2727
onCancelClick,
2828
onSubmitClick,
2929
}: VoiceMessageInputWrapperProps): React.ReactElement => {
30+
const uuid = useRef<string>(uuidv4()).current;
3031
const [audioFile, setAudioFile] = useState<File>(null);
31-
const [uuid] = useState<string>(uuidv4());
3232
const [voiceInputState, setVoiceInputState] = useState<VoiceMessageInputStatus>(VoiceMessageInputStatus.READY_TO_RECORD);
33-
const [isSubmited, setSubmit] = useState(false);
33+
const [isSubmitted, setSubmit] = useState(false);
3434
const [isDisabled, setDisabled] = useState(false);
3535
const [showModal, setShowModal] = useState(false);
3636
const { stringSet } = useLocalization();
@@ -73,13 +73,15 @@ export const VoiceMessageInputWrapper = ({
7373
}
7474
}, [channel?.myRole, channel?.isFrozen, channel?.myMutedState]);
7575

76+
// call onSubmitClick when submit button is clicked and recorded audio file is created
7677
useEffect(() => {
77-
if (isSubmited && audioFile) {
78+
if (isSubmitted && audioFile) {
7879
onSubmitClick(audioFile, recordingTime);
7980
setSubmit(false);
8081
setAudioFile(null);
8182
}
82-
}, [isSubmited, audioFile, recordingTime]);
83+
}, [isSubmitted, audioFile, recordingTime]);
84+
// operate which control button should be displayed
8385
useEffect(() => {
8486
if (audioFile) {
8587
if (recordingTime < minRecordingTime) {
@@ -91,15 +93,18 @@ export const VoiceMessageInputWrapper = ({
9193
setVoiceInputState(VoiceMessageInputStatus.READY_TO_PLAY);
9294
}
9395
}
94-
}, [isSubmited, audioFile, recordingTime, playingStatus]);
96+
}, [audioFile, recordingTime, playingStatus]);
9597

9698
return (
9799
<div className="sendbird-voice-message-input-wrapper">
98100
<VoiceMessageInput
99101
currentValue={recordingStatus === VoiceRecorderStatus.COMPLETED ? playbackTime : recordingTime}
100102
maximumValue={recordingStatus === VoiceRecorderStatus.COMPLETED ? recordingTime : recordingLimit}
101103
currentType={voiceInputState}
102-
onCancelClick={onCancelClick}
104+
onCancelClick={() => {
105+
onCancelClick();
106+
cancel();
107+
}}
103108
onSubmitClick={() => {
104109
if (isDisabled) {
105110
setShowModal(true);

src/smart-components/ChannelList/components/ChannelPreview/channel-preview.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
margin-left: 16px;
5656
@include mobile() {
5757
position: relative;
58+
max-width: calc(100% - 72px);
5859
}
5960

6061
.sendbird-channel-preview__content__upper {

src/smart-components/ChannelList/components/ChannelPreview/index.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,7 @@ const ChannelPreview: React.FC<ChannelPreviewInterface> = ({
114114
type={LabelTypography.SUBTITLE_2}
115115
color={LabelColors.ONBACKGROUND_1}
116116
>
117-
<div>
118-
{channelName}
119-
</div>
117+
{channelName}
120118
</Label>
121119
<Label
122120
className="sendbird-channel-preview__content__upper__header__total-members"

src/smart-components/OpenChannel/components/OpenChannelMessageList/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import './openchannel-message-list.scss';
22

33
import React, { ReactElement, useRef, useState, useMemo } from 'react';
4-
import { FileMessage, UserMessage } from '@sendbird/chat/message';
4+
import { UserMessage } from '@sendbird/chat/message';
55
import isSameDay from 'date-fns/isSameDay';
66

77
import Icon, { IconTypes, IconColors } from '../../../../ui/Icon';

src/ui/MessageContent/index.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
.sendbird-message-content__middle {
1616
max-width: 400px;
1717
@include mobile() {
18-
max-width: calc(100vw - 100px);
18+
max-width: calc(100vw - 140px);
1919
}
2020
}
2121

0 commit comments

Comments
 (0)