From 0d4ae02135cc881cccf619e44c30579bf3150a6e Mon Sep 17 00:00:00 2001 From: Vishal Narkhede Date: Fri, 24 Nov 2023 16:20:43 +0100 Subject: [PATCH] fix: update editing and quoted state within context correctly --- package/src/components/Channel/Channel.tsx | 9 +++++---- .../hooks/useCreateInputMessageInputContext.ts | 11 ++--------- .../hooks/useCreateMessageInputContext.ts | 4 ++-- .../src/contexts/messagesContext/MessagesContext.tsx | 4 ++-- 4 files changed, 11 insertions(+), 17 deletions(-) diff --git a/package/src/components/Channel/Channel.tsx b/package/src/components/Channel/Channel.tsx index 9e82389378..c8c814fcbf 100644 --- a/package/src/components/Channel/Channel.tsx +++ b/package/src/components/Channel/Channel.tsx @@ -1587,15 +1587,16 @@ const ChannelWithContext = < : client.updateMessage(updatedMessage); const setEditingState: MessagesContextValue['setEditingState'] = ( - message, + messageOrBoolean, ) => { - setEditing(message); + clearQuotedMessageState(); + setEditing(messageOrBoolean); }; const setQuotedMessageState: MessagesContextValue['setQuotedMessageState'] = ( - message, + messageOrBoolean, ) => { - setQuotedMessage(message); + setQuotedMessage(messageOrBoolean); }; const clearEditingState: InputMessageInputContextValue['clearEditingState'] = diff --git a/package/src/components/Channel/hooks/useCreateInputMessageInputContext.ts b/package/src/components/Channel/hooks/useCreateInputMessageInputContext.ts index 456704e144..18f1af0b7c 100644 --- a/package/src/components/Channel/hooks/useCreateInputMessageInputContext.ts +++ b/package/src/components/Channel/hooks/useCreateInputMessageInputContext.ts @@ -53,7 +53,7 @@ export const useCreateInputMessageInputContext = < */ channelId?: string; }) => { - const editingExists = !!editing; + const editingDep = typeof editing === 'boolean' ? editing : editing?.id; const quotedMessageId = quotedMessage ? typeof quotedMessage === 'boolean' ? '' @@ -103,14 +103,7 @@ export const useCreateInputMessageInputContext = < ShowThreadMessageInChannelButton, UploadProgressIndicator, }), - [ - compressImageQuality, - channelId, - editingExists, - initialValue, - maxMessageLength, - quotedMessageId, - ], + [compressImageQuality, channelId, editingDep, initialValue, maxMessageLength, quotedMessageId], ); return inputMessageInputContext; diff --git a/package/src/contexts/messageInputContext/hooks/useCreateMessageInputContext.ts b/package/src/contexts/messageInputContext/hooks/useCreateMessageInputContext.ts index 5b428c1ff6..2d00bdb9d2 100644 --- a/package/src/contexts/messageInputContext/hooks/useCreateMessageInputContext.ts +++ b/package/src/contexts/messageInputContext/hooks/useCreateMessageInputContext.ts @@ -95,7 +95,7 @@ export const useCreateMessageInputContext = < UploadProgressIndicator, }: MessageInputContextValue & Pick, 'thread'>) => { - const editingExists = !!editing; + const editingdep = typeof editing === 'boolean' ? editing : editing?.id; const fileUploadsValue = fileUploads .map(({ duration, paused, progress, state }) => `${state},${paused},${progress},${duration}`) .join(); @@ -198,7 +198,7 @@ export const useCreateMessageInputContext = < }), [ cooldownEndsAt, - editingExists, + editingdep, fileUploadsValue, giphyActive, imageUploadsValue, diff --git a/package/src/contexts/messagesContext/MessagesContext.tsx b/package/src/contexts/messagesContext/MessagesContext.tsx index 1686b5d87e..59cdab88b0 100644 --- a/package/src/contexts/messagesContext/MessagesContext.tsx +++ b/package/src/contexts/messagesContext/MessagesContext.tsx @@ -234,8 +234,8 @@ export type MessagesContextValue< */ ScrollToBottomButton: React.ComponentType; sendReaction: (type: string, messageId: string) => Promise; - setEditingState: (message: MessageType) => void; - setQuotedMessageState: (message: MessageType) => void; + setEditingState: (message: MessageType | boolean) => void; + setQuotedMessageState: (message: MessageType | boolean) => void; supportedReactions: ReactionData[]; /** * UI component for TypingIndicator