Skip to content

Commit

Permalink
Add MessageActions to ComponentContext, deprecate old stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
arnautov-anton committed Oct 28, 2024
1 parent b2363e3 commit 7f2ec2c
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 7 deletions.
3 changes: 3 additions & 0 deletions src/components/Channel/Channel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ type ChannelPropsForwardedToComponentContext<
| 'LinkPreviewList'
| 'LoadingIndicator'
| 'Message'
| 'MessageActions'
| 'MessageBouncePrompt'
| 'MessageDeleted'
| 'MessageListNotifications'
Expand Down Expand Up @@ -1226,6 +1227,7 @@ const ChannelInner = <
LinkPreviewList: props.LinkPreviewList,
LoadingIndicator: props.LoadingIndicator,
Message: props.Message,
MessageActions: props.MessageActions,
MessageBouncePrompt: props.MessageBouncePrompt,
MessageDeleted: props.MessageDeleted,
MessageListNotifications: props.MessageListNotifications,
Expand Down Expand Up @@ -1275,6 +1277,7 @@ const ChannelInner = <
props.LinkPreviewList,
props.LoadingIndicator,
props.Message,
props.MessageActions,
props.MessageBouncePrompt,
props.MessageDeleted,
props.MessageListNotifications,
Expand Down
3 changes: 3 additions & 0 deletions src/components/Message/MessageOptions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ const UnMemoizedMessageOptions = <
);
};

/**
* @deprecated Use MessageActions_UNSTABLE (`MessageActions` component) instead.
*/
export const MessageOptions = React.memo(
UnMemoizedMessageOptions,
) as typeof UnMemoizedMessageOptions;
8 changes: 5 additions & 3 deletions src/components/Message/MessageSimple.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,15 @@ const MessageSimpleWithContext = <
Attachment = DefaultAttachment,
Avatar = DefaultAvatar,
EditMessageInput = DefaultEditMessageForm,
MessageOptions = DefaultMessageOptions,
// TODO: remove this "passthrough" in the next
// major release and use the new default instead
MessageActions = MessageOptions,
MessageDeleted = DefaultMessageDeleted,
MessageBouncePrompt = DefaultMessageBouncePrompt,
MessageOptions = DefaultMessageOptions,
MessageRepliesCountButton = DefaultMessageRepliesCountButton,
MessageStatus = DefaultMessageStatus,
MessageTimestamp = DefaultMessageTimestamp,

ReactionsList = DefaultReactionList,
PinIndicator,
} = useComponentContext<StreamChatGenerics>('MessageSimple');
Expand Down Expand Up @@ -171,7 +173,7 @@ const MessageSimpleWithContext = <
onClick={handleClick}
onKeyUp={handleClick}
>
<MessageOptions />
<MessageActions />
<div className='str-chat__message-reactions-host'>
{hasReactions && <ReactionsList reverse />}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,9 @@ export const DefaultDropdownActionButton = ({

/**
* Base filter hook which covers actions of type `delete`, `edit`,
* `flag`, `markAsUnread`, `mute`, `quote`, `react` and `reply` and whether
* the rendered message is a reply (replies are limited to certain actions).
* `flag`, `markAsUnread`, `mute`, `quote`, `react` and `reply`, whether
* the rendered message is a reply (replies are limited to certain actions) and
* whether the message has appropriate type and status.
*/
export const useBaseMessageActionSetFilter = (
messageActionSet: MessageAction[],
Expand Down Expand Up @@ -266,6 +267,7 @@ export const useSplitMessageActionSet = (messageActionSet: MessageAction[]) =>
return { quickActionSet, dropdownActionSet } as const;
}, [messageActionSet]);

// TODO: allow passing down customWrapperClass
export const MessageActions = ({
disableBaseMessageActionSetFilter = false,
messageActionSet = defaultMessageActionSet,
Expand Down
2 changes: 1 addition & 1 deletion src/components/MessageActions/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export * from './MessageActions';
export * from './MessageActionsBox';
export * from './CustomMessageActionsList';
export * as MessageActions_UNSTABLE from './MessageActions.new';
export * as MessageActions_UNSTABLE from './MessageActions_UNSTABLE';
8 changes: 7 additions & 1 deletion src/context/ComponentContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ export type ComponentContextValue<
LoadingIndicator?: React.ComponentType<LoadingIndicatorProps>;
/** Custom UI component to display a message in the standard `MessageList`, defaults to and accepts the same props as: [MessageSimple](https://github.com/GetStream/stream-chat-react/blob/master/src/components/Message/MessageSimple.tsx) */
Message?: React.ComponentType<MessageUIComponentProps<StreamChatGenerics>>;
/** Custom UI component for message actions popup, accepts no props, all the defaults are set within [MessageActions_UNSTABLE](https://github.com/GetStream/stream-chat-react/blob/master/src/components/MessageActions/MessageActions_UNSTABLE.tsx) (`MessageActions` component) */
MessageActions?: React.ComponentType;
/** Custom UI component to display the contents of a bounced message modal. Usually it allows to retry, edit, or delete the message. Defaults to and accepts the same props as: [MessageBouncePrompt](https://github.com/GetStream/stream-chat-react/blob/master/src/components/MessageBounce/MessageBouncePrompt.tsx) */
MessageBouncePrompt?: React.ComponentType<MessageBouncePromptProps>;
/** Custom UI component for a deleted message, defaults to and accepts same props as: [MessageDeleted](https://github.com/GetStream/stream-chat-react/blob/master/src/components/Message/MessageDeleted.tsx) */
Expand All @@ -111,7 +113,11 @@ export type ComponentContextValue<
MessageListNotifications?: React.ComponentType<MessageListNotificationsProps>;
/** Custom UI component to display a notification when scrolled up the list and new messages arrive, defaults to and accepts same props as [MessageNotification](https://github.com/GetStream/stream-chat-react/blob/master/src/components/MessageList/MessageNotification.tsx) */
MessageNotification?: React.ComponentType<MessageNotificationProps>;
/** Custom UI component for message options popup, defaults to and accepts same props as: [MessageOptions](https://github.com/GetStream/stream-chat-react/blob/master/src/components/Message/MessageOptions.tsx) */
/**
* Custom UI component for message options popup, defaults to and accepts same props as: [MessageOptions](https://github.com/GetStream/stream-chat-react/blob/master/src/components/Message/MessageOptions.tsx)
*
* @deprecated Use MessageActions property instead.
*/
MessageOptions?: React.ComponentType<MessageOptionsProps<StreamChatGenerics>>;
/** Custom UI component to display message replies, defaults to and accepts same props as: [MessageRepliesCountButton](https://github.com/GetStream/stream-chat-react/blob/master/src/components/Message/MessageRepliesCountButton.tsx) */
MessageRepliesCountButton?: React.ComponentType<MessageRepliesCountButtonProps>;
Expand Down

0 comments on commit 7f2ec2c

Please sign in to comment.