Skip to content

Commit c9a10dd

Browse files
committed
fix: close poll modal before send to avoid reset on the UI
1 parent b587b74 commit c9a10dd

File tree

4 files changed

+9
-25
lines changed

4 files changed

+9
-25
lines changed

package/src/components/MessageInput/MessageInput.tsx

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,6 @@ type MessageInputPropsWithContext = Partial<
160160
| 'CommandInput'
161161
| 'InputReplyStateHeader'
162162
| 'maxNumberOfFiles'
163-
| 'resetInput'
164163
| 'SendButton'
165164
| 'ShowThreadMessageInChannelButton'
166165
| 'StartAudioRecordingButton'
@@ -226,7 +225,6 @@ const MessageInputWithContext = (props: MessageInputPropsWithContext) => {
226225
maxNumberOfFiles,
227226
members,
228227
Reply,
229-
resetInput,
230228
SendButton,
231229
sendMessage,
232230
showPollCreationDialog,
@@ -302,10 +300,9 @@ const MessageInputWithContext = (props: MessageInputPropsWithContext) => {
302300
*/
303301
if (
304302
!editing &&
305-
(command || attachments.length > 0 || mentionedUsers.length > 0 || availableUploadSlots) &&
306-
resetInput
303+
(command || attachments.length > 0 || mentionedUsers.length > 0 || availableUploadSlots)
307304
) {
308-
resetInput();
305+
messageComposer.clear();
309306
}
310307
// eslint-disable-next-line react-hooks/exhaustive-deps
311308
}, [editingExists]);
@@ -818,7 +815,6 @@ export const MessageInput = (props: MessageInputProps) => {
818815
InputReplyStateHeader,
819816
maxNumberOfFiles,
820817
openPollCreationDialog,
821-
resetInput,
822818
SendButton,
823819
sendMessage,
824820
SendMessageDisallowedIndicator,
@@ -892,7 +888,6 @@ export const MessageInput = (props: MessageInputProps) => {
892888
members,
893889
openPollCreationDialog,
894890
Reply,
895-
resetInput,
896891
selectedPicker,
897892
SendButton,
898893
sendMessage,

package/src/components/Poll/CreatePollContent.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,13 @@ export const CreatePoll = ({
162162

163163
const createAndSendPoll = useCallback(async () => {
164164
try {
165+
/**
166+
* The poll is emptied inside the createPoll method(using initState) which is why we close the dialog
167+
* first so that it doesn't look weird.
168+
*/
169+
closePollCreationDialog?.();
165170
await messageComposer.createPoll();
166171
await sendMessage();
167-
closePollCreationDialog?.();
168172
} catch (error) {
169173
console.log('Error creating a poll and sending a message:', error);
170174
}

package/src/contexts/messageInputContext/MessageInputContext.tsx

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import { Alert, Keyboard, Linking, TextInput, TextInputProps } from 'react-nativ
1111

1212
import { BottomSheetHandleProps } from '@gorhom/bottom-sheet';
1313
import {
14-
Attachment,
1514
createApplyCommandSettingsMiddleware,
1615
createCommandInjectionMiddleware,
1716
createDraftCommandInjectionMiddleware,
@@ -90,7 +89,6 @@ export type LocalMessageInputContext = {
9089
*/
9190
pickAndUploadImageFromNativePicker: () => Promise<void>;
9291
pickFile: () => Promise<void>;
93-
resetInput: (pendingAttachments?: Attachment[]) => void;
9492
sendMessage: (params?: { customMessageData?: Partial<Message> }) => Promise<void>;
9593
sendThreadMessageInChannel: boolean;
9694
/**
@@ -595,16 +593,6 @@ export const MessageInputProvider = ({
595593
}
596594
}, [closeAttachmentPicker, openAttachmentPicker, selectedPicker]);
597595

598-
const resetInput = useStableCallback(() => {
599-
if (!value.editing) {
600-
messageComposer.clear();
601-
}
602-
603-
if (value.editing) {
604-
value.clearEditingState();
605-
}
606-
});
607-
608596
const sendMessage = useStableCallback(async () => {
609597
startCooldown();
610598

@@ -618,14 +606,14 @@ export const MessageInputProvider = ({
618606

619607
if (editedMessage && editedMessage.type !== 'error') {
620608
try {
621-
resetInput();
609+
value.clearEditingState();
622610
await value.editMessage({ localMessage, options: sendOptions });
623611
} catch (error) {
624612
console.log('Failed to edit message:', error);
625613
}
626614
} else {
627615
try {
628-
resetInput();
616+
messageComposer.clear();
629617
await value.sendMessage({
630618
localMessage: {
631619
...localMessage,
@@ -686,7 +674,6 @@ export const MessageInputProvider = ({
686674
openFilePicker: pickFile,
687675
pickAndUploadImageFromNativePicker,
688676
pickFile,
689-
resetInput,
690677
sendThreadMessageInChannel,
691678
setInputBoxRef,
692679
setSendThreadMessageInChannel,

package/src/contexts/messageInputContext/hooks/useCreateMessageInputContext.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ export const useCreateMessageInputContext = ({
6363
openPollCreationDialog,
6464
pickAndUploadImageFromNativePicker,
6565
pickFile,
66-
resetInput,
6766
SendButton,
6867
sendMessage,
6968
SendMessageDisallowedIndicator,
@@ -146,7 +145,6 @@ export const useCreateMessageInputContext = ({
146145
openPollCreationDialog,
147146
pickAndUploadImageFromNativePicker,
148147
pickFile,
149-
resetInput,
150148
SendButton,
151149
sendMessage,
152150
SendMessageDisallowedIndicator,

0 commit comments

Comments
 (0)