Skip to content

Commit c598a70

Browse files
Finalize
1 parent 72df08e commit c598a70

4 files changed

Lines changed: 33 additions & 11 deletions

File tree

src/components/Reactions/MessageReactions.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { MAX_MESSAGE_REACTIONS_TO_FETCH } from '../Message/hooks';
2121
import type { ReactionGroupResponse, ReactionResponse } from 'stream-chat';
2222
import type { ReactionsComparator, ReactionType } from './types';
2323
import { DialogAnchor, useDialogIsOpen, useDialogOnNearestManager } from '../Dialog';
24+
import { ReactionSelector } from './ReactionSelector';
2425

2526
export type MessageReactionsProps = Partial<
2627
Pick<MessageContextValue, 'handleFetchReactions' | 'reactionDetailsSort'>
@@ -66,7 +67,6 @@ const UnMemoizedMessageReactions = (props: MessageReactionsProps) => {
6667
capLimit: { clustered: capLimitClustered = 5, segmented: capLimitSegmented = 4 } = {},
6768
flipHorizontalPosition = false,
6869
handleFetchReactions,
69-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
7070
reactionDetailsSort,
7171
verticalPosition = 'top',
7272
visualStyle = 'clustered',
@@ -89,7 +89,9 @@ const UnMemoizedMessageReactions = (props: MessageReactionsProps) => {
8989
const { isMyMessage, message } = useMessageContext('MessageReactions');
9090

9191
const divRef = useRef<ComponentRef<'div'>>(null);
92-
const dialogId = `message-reactions-detail-${message.id}`;
92+
const dialogId = DefaultMessageReactionsDetail.getDialogId({
93+
messageId: message.id,
94+
});
9395
const { dialog, dialogManager } = useDialogOnNearestManager({ id: dialogId });
9496
const isDialogOpen = useDialogIsOpen(dialogId, dialogManager?.id);
9597

@@ -225,6 +227,7 @@ const UnMemoizedMessageReactions = (props: MessageReactionsProps) => {
225227
<MessageReactionsDetail
226228
handleFetchReactions={handleFetchReactions}
227229
onSelectedReactionTypeChange={setSelectedReactionType}
230+
reactionDetailsSort={reactionDetailsSort}
228231
reactionGroups={reactionGroups}
229232
reactions={existingReactions}
230233
selectedReactionType={selectedReactionType}

src/components/Reactions/MessageReactionsDetail.tsx

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,13 @@ export const MessageReactionsDetailLoadingIndicator = () => {
4545
return <>{elements}</>;
4646
};
4747

48-
export function MessageReactionsDetail({
48+
interface MessageReactionsDetailInterface {
49+
(props: MessageReactionsDetailProps): React.ReactNode;
50+
displayName: string;
51+
getDialogId: (_: { messageId: string }) => string;
52+
}
53+
54+
export const MessageReactionsDetail: MessageReactionsDetailInterface = ({
4955
handleFetchReactions,
5056
handleReaction,
5157
onSelectedReactionTypeChange,
@@ -55,13 +61,14 @@ export function MessageReactionsDetail({
5561
reactions,
5662
selectedReactionType,
5763
totalReactionCount,
58-
}: MessageReactionsDetailProps) {
64+
}) => {
5965
const [extendedReactionListOpen, setExtendedReactionListOpen] = useState(false);
6066
const { client } = useChatContext();
6167
const {
6268
Avatar = DefaultAvatar,
6369
LoadingIndicator = MessageReactionsDetailLoadingIndicator,
6470
reactionOptions = defaultReactionOptions,
71+
ReactionSelectorExtendedList = ReactionSelector.ExtendedList,
6572
} = useComponentContext(MessageReactionsDetail.name);
6673
const { t } = useTranslationContext();
6774

@@ -91,8 +98,8 @@ export function MessageReactionsDetail({
9198
className='str-chat__message-reactions-detail'
9299
data-testid='message-reactions-detail'
93100
>
94-
<ReactionSelector.ExtendedList
95-
dialogId={`message-reactions-detail-${message.id}`}
101+
<ReactionSelectorExtendedList
102+
dialogId={MessageReactionsDetail.getDialogId({ messageId: message.id })}
96103
handleReaction={handleReaction}
97104
own_reactions={own_reactions}
98105
/>
@@ -220,4 +227,9 @@ export function MessageReactionsDetail({
220227
</div>
221228
</div>
222229
);
223-
}
230+
};
231+
232+
MessageReactionsDetail.displayName = 'MessageReactionsDetail';
233+
234+
MessageReactionsDetail.getDialogId = ({ messageId }) =>
235+
`message-reactions-detail-${messageId}`;

src/components/Reactions/ReactionSelector.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,10 @@ export const ReactionSelector: ReactionSelectorInterface = (props) => {
3333
const { handleReaction: propHandleReaction, own_reactions: propOwnReactions } = props;
3434
const [extendedListOpen, setExtendedListOpen] = useState(false);
3535

36-
const { reactionOptions = defaultReactionOptions } =
37-
useComponentContext('ReactionSelector');
36+
const {
37+
reactionOptions = defaultReactionOptions,
38+
ReactionSelectorExtendedList = ReactionSelector.ExtendedList,
39+
} = useComponentContext('ReactionSelector');
3840

3941
const {
4042
closeReactionSelectorOnClick,
@@ -116,7 +118,7 @@ export const ReactionSelector: ReactionSelectorInterface = (props) => {
116118
</>
117119
)}
118120
{extendedListOpen && (
119-
<ReactionSelector.ExtendedList {...props} dialogId={dialogId} />
121+
<ReactionSelectorExtendedList {...props} dialogId={dialogId} />
120122
)}
121123
</div>
122124
);

src/context/ComponentContext.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import type { PropsWithChildren } from 'react';
1+
import type { ComponentProps, PropsWithChildren } from 'react';
22
import React, { useContext } from 'react';
33

4+
45
import {
56
type AttachmentPreviewListProps,
67
type AttachmentProps,
@@ -43,6 +44,7 @@ import {
4344
type PollOptionSelectorProps,
4445
type QuotedMessagePreviewProps,
4546
type ReactionOptions,
47+
type ReactionSelector,
4648
type ReactionSelectorProps,
4749
type RecordingPermissionDeniedNotificationProps,
4850
type ReminderNotificationProps,
@@ -211,6 +213,9 @@ export type ComponentContextValue = {
211213
reactionOptions?: ReactionOptions;
212214
/** Custom UI component to display the reaction selector, defaults to and accepts same props as: [ReactionSelector](https://github.com/GetStream/stream-chat-react/blob/master/src/components/Reactions/ReactionSelector.tsx) */
213215
ReactionSelector?: React.ForwardRefExoticComponent<ReactionSelectorProps>;
216+
ReactionSelectorExtendedList?: React.ComponentType<
217+
ComponentProps<(typeof ReactionSelector)['ExtendedList']>
218+
>;
214219
/** Custom UI component to display the list of reactions on a message, defaults to and accepts same props as: [MessageReactions](https://github.com/GetStream/stream-chat-react/blob/master/src/components/Reactions/MessageReactions.tsx) */
215220
MessageReactions?: React.ComponentType<MessageReactionsProps>;
216221
/** Custom UI component to display the reactions modal, defaults to and accepts same props as: [MessageReactionsDetail](https://github.com/GetStream/stream-chat-react/blob/master/src/components/Reactions/MessageReactionsDetail.tsx) */

0 commit comments

Comments
 (0)