Skip to content

Commit

Permalink
fix: update editing and quoted state within context correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
vishalnarkhede committed Nov 24, 2023
1 parent be241e1 commit 0d4ae02
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 17 deletions.
9 changes: 5 additions & 4 deletions package/src/components/Channel/Channel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1587,15 +1587,16 @@ const ChannelWithContext = <
: client.updateMessage(updatedMessage);

const setEditingState: MessagesContextValue<StreamChatGenerics>['setEditingState'] = (
message,
messageOrBoolean,
) => {
setEditing(message);
clearQuotedMessageState();
setEditing(messageOrBoolean);
};

const setQuotedMessageState: MessagesContextValue<StreamChatGenerics>['setQuotedMessageState'] = (
message,
messageOrBoolean,
) => {
setQuotedMessage(message);
setQuotedMessage(messageOrBoolean);
};

const clearEditingState: InputMessageInputContextValue<StreamChatGenerics>['clearEditingState'] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
? ''
Expand Down Expand Up @@ -103,14 +103,7 @@ export const useCreateInputMessageInputContext = <
ShowThreadMessageInChannelButton,
UploadProgressIndicator,
}),
[
compressImageQuality,
channelId,
editingExists,
initialValue,
maxMessageLength,
quotedMessageId,
],
[compressImageQuality, channelId, editingDep, initialValue, maxMessageLength, quotedMessageId],
);

return inputMessageInputContext;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export const useCreateMessageInputContext = <
UploadProgressIndicator,
}: MessageInputContextValue<StreamChatGenerics> &
Pick<ThreadContextValue<StreamChatGenerics>, '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();
Expand Down Expand Up @@ -198,7 +198,7 @@ export const useCreateMessageInputContext = <
}),
[
cooldownEndsAt,
editingExists,
editingdep,
fileUploadsValue,
giphyActive,
imageUploadsValue,
Expand Down
4 changes: 2 additions & 2 deletions package/src/contexts/messagesContext/MessagesContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,8 @@ export type MessagesContextValue<
*/
ScrollToBottomButton: React.ComponentType<ScrollToBottomButtonProps>;
sendReaction: (type: string, messageId: string) => Promise<void>;
setEditingState: (message: MessageType<StreamChatGenerics>) => void;
setQuotedMessageState: (message: MessageType<StreamChatGenerics>) => void;
setEditingState: (message: MessageType<StreamChatGenerics> | boolean) => void;
setQuotedMessageState: (message: MessageType<StreamChatGenerics> | boolean) => void;
supportedReactions: ReactionData[];
/**
* UI component for TypingIndicator
Expand Down

0 comments on commit 0d4ae02

Please sign in to comment.