Skip to content

Commit 7c0751d

Browse files
committed
fix: poll creation and optimistic updates
1 parent efcd573 commit 7c0751d

File tree

5 files changed

+12
-11
lines changed

5 files changed

+12
-11
lines changed

package/src/components/MessageInput/SendButton.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export type SendButtonProps = Partial<Pick<MessageInputContextValue, 'sendMessag
2222

2323
// TODO: Comment out once the commands PR has been merged on the LLC
2424
// @ts-ignore
25+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
2526
const textComposerStateSelector = (state: TextComposerState) => ({
2627
// TODO: Comment out once the commands PR has been merged on the LLC
2728
// command: state.command,

package/src/components/MessageInput/__tests__/AudioAttachmentUploadPreview.test.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,7 @@ import { act, fireEvent, render, screen, waitFor } from '@testing-library/react-
44

55
import { OverlayProvider } from '../../../contexts';
66
import { initiateClientWithChannels } from '../../../mock-builders/api/initiateClientWithChannels';
7-
import {
8-
generateAudioAttachment,
9-
generateFileAttachment,
10-
generateVideoAttachment,
11-
} from '../../../mock-builders/attachments';
7+
import { generateAudioAttachment } from '../../../mock-builders/attachments';
128

139
import { FileState } from '../../../utils/utils';
1410
import { Channel } from '../../Channel/Channel';

package/src/components/Poll/CreatePollContent.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -158,13 +158,13 @@ export const CreatePoll = ({
158158

159159
const createAndSendPoll = useCallback(async () => {
160160
try {
161-
/**
162-
* The poll is emptied inside the createPoll method(using initState) which is why we close the dialog
163-
* first so that it doesn't look weird.
164-
*/
165-
closePollCreationDialog?.();
166161
await messageComposer.createPoll();
167162
await sendMessage();
163+
closePollCreationDialog?.();
164+
// it's important that the reset of the pollComposer state happens
165+
// after we've already closed the modal; as otherwise we'd get weird
166+
// UI behaviour.
167+
messageComposer.pollComposer.initState();
168168
} catch (error) {
169169
console.log('Error creating a poll and sending a message:', error);
170170
}

package/src/contexts/messageInputContext/MessageInputContext.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -624,7 +624,10 @@ export const MessageInputProvider = ({
624624
}
625625
} else {
626626
try {
627-
messageComposer.clear();
627+
// we will handle this specific case in the poll creation dialog
628+
if (!localMessage.poll_id) {
629+
messageComposer.clear();
630+
}
628631
await value.sendMessage({
629632
localMessage: {
630633
...localMessage,

package/src/utils/setupCommandUIMiddleware.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88

99
// TODO: Comment out once the commands PR has been merged on the LLC
1010
// @ts-ignore
11+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
1112
export const setupCommandUIMiddleware = (messageComposer: MessageComposer) => {
1213
// TODO: Comment out once the commands PR has been merged on the LLC
1314
// messageComposer.compositionMiddlewareExecutor.insert({

0 commit comments

Comments
 (0)