Skip to content

Commit b5019f1

Browse files
committed
chore: move components down to MessagesContext
1 parent 029d4d9 commit b5019f1

File tree

9 files changed

+43
-30
lines changed

9 files changed

+43
-30
lines changed

package/src/components/AttachmentPicker/components/AttachmentPickerSelectionBar.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import React from 'react';
22
import { StyleSheet, TouchableOpacity, View } from 'react-native';
33

4-
import { useChannelContext, useOwnCapabilitiesContext } from '../../../contexts';
4+
import {
5+
useChannelContext,
6+
useMessagesContext,
7+
useOwnCapabilitiesContext,
8+
} from '../../../contexts';
59
import { useAttachmentPickerContext } from '../../../contexts/attachmentPickerContext/AttachmentPickerContext';
610
import { useMessageInputContext } from '../../../contexts/messageInputContext/MessageInputContext';
711
import { useTheme } from '../../../contexts/themeContext/ThemeContext';
@@ -38,7 +42,8 @@ export const AttachmentPickerSelectionBar = () => {
3842
sendMessage,
3943
takeAndUploadImage,
4044
} = useMessageInputContext();
41-
const { hasCreatePoll, threadList } = useChannelContext();
45+
const { threadList } = useChannelContext();
46+
const { hasCreatePoll } = useMessagesContext();
4247
const ownCapabilities = useOwnCapabilitiesContext();
4348

4449
const {

package/src/components/Channel/Channel.tsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -230,10 +230,6 @@ export type ChannelPropsWithContext<
230230
| 'maxTimeBetweenGroupedMessages'
231231
| 'NetworkDownIndicator'
232232
| 'StickyHeader'
233-
| 'Poll'
234-
| 'PollButtons'
235-
| 'PollHeader'
236-
| 'hasCreatePoll'
237233
>
238234
> &
239235
Pick<ChatContextValue<StreamChatGenerics>, 'client' | 'enableOfflineSupport'> &
@@ -334,6 +330,10 @@ export type ChannelPropsWithContext<
334330
| 'TypingIndicatorContainer'
335331
| 'UrlPreview'
336332
| 'VideoThumbnail'
333+
| 'Poll'
334+
| 'PollButtons'
335+
| 'PollHeader'
336+
| 'hasCreatePoll'
337337
>
338338
> &
339339
Partial<Pick<ThreadContextValue<StreamChatGenerics>, 'allowThreadMessagesInChannel'>> & {
@@ -2240,7 +2240,6 @@ const ChannelWithContext = <
22402240
giphyEnabled:
22412241
giphyEnabled ??
22422242
!!(clientChannelConfig?.commands || [])?.some((command) => command.name === 'giphy'),
2243-
hasCreatePoll: hasCreatePoll === undefined ? true : hasCreatePoll,
22442243
hideDateSeparators,
22452244
hideStickyDateHeader,
22462245
isAdmin,
@@ -2256,9 +2255,6 @@ const ChannelWithContext = <
22562255
maxTimeBetweenGroupedMessages,
22572256
members,
22582257
NetworkDownIndicator,
2259-
Poll,
2260-
PollButtons,
2261-
PollHeader,
22622258
read,
22632259
reloadChannel,
22642260
scrollToFirstUnreadThreshold,
@@ -2395,6 +2391,7 @@ const ChannelWithContext = <
23952391
handleReaction,
23962392
handleRetry,
23972393
handleThreadReply,
2394+
hasCreatePoll: hasCreatePoll === undefined ? true : hasCreatePoll,
23982395
ImageLoadingFailedIndicator,
23992396
ImageLoadingIndicator,
24002397
initialScrollToFirstUnreadMessage: !messageId && initialScrollToFirstUnreadMessage, // when messageId is set, we scroll to the messageId instead of first unread
@@ -2428,6 +2425,9 @@ const ChannelWithContext = <
24282425
onPressInMessage,
24292426
onPressMessage,
24302427
OverlayReactionList,
2428+
Poll,
2429+
PollButtons,
2430+
PollHeader,
24312431
ReactionList,
24322432
removeMessage,
24332433
Reply,

package/src/components/Channel/hooks/useCreateChannelContext.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ export const useCreateChannelContext = <
1313
enforceUniqueReaction,
1414
error,
1515
giphyEnabled,
16-
hasCreatePoll,
1716
hideDateSeparators,
1817
hideStickyDateHeader,
1918
isAdmin,
@@ -29,9 +28,6 @@ export const useCreateChannelContext = <
2928
maxTimeBetweenGroupedMessages,
3029
members,
3130
NetworkDownIndicator,
32-
Poll,
33-
PollButtons,
34-
PollHeader,
3531
read,
3632
reloadChannel,
3733
scrollToFirstUnreadThreshold,
@@ -61,7 +57,6 @@ export const useCreateChannelContext = <
6157
enforceUniqueReaction,
6258
error,
6359
giphyEnabled,
64-
hasCreatePoll,
6560
hideDateSeparators,
6661
hideStickyDateHeader,
6762
isAdmin,
@@ -77,9 +72,6 @@ export const useCreateChannelContext = <
7772
maxTimeBetweenGroupedMessages,
7873
members,
7974
NetworkDownIndicator,
80-
Poll,
81-
PollButtons,
82-
PollHeader,
8375
read,
8476
reloadChannel,
8577
scrollToFirstUnreadThreshold,
@@ -106,7 +98,6 @@ export const useCreateChannelContext = <
10698
targetedMessage,
10799
threadList,
108100
watcherCount,
109-
hasCreatePoll,
110101
],
111102
);
112103

package/src/components/Channel/hooks/useCreateMessagesContext.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export const useCreateMessagesContext = <
4343
handleReaction,
4444
handleRetry,
4545
handleThreadReply,
46+
hasCreatePoll,
4647
ImageLoadingFailedIndicator,
4748
ImageLoadingIndicator,
4849
initialScrollToFirstUnreadMessage,
@@ -76,6 +77,9 @@ export const useCreateMessagesContext = <
7677
onPressInMessage,
7778
onPressMessage,
7879
OverlayReactionList,
80+
Poll,
81+
PollButtons,
82+
PollHeader,
7983
ReactionList,
8084
removeMessage,
8185
Reply,
@@ -141,6 +145,7 @@ export const useCreateMessagesContext = <
141145
handleReaction,
142146
handleRetry,
143147
handleThreadReply,
148+
hasCreatePoll,
144149
ImageLoadingFailedIndicator,
145150
ImageLoadingIndicator,
146151
initialScrollToFirstUnreadMessage,
@@ -174,6 +179,9 @@ export const useCreateMessagesContext = <
174179
onPressInMessage,
175180
onPressMessage,
176181
OverlayReactionList,
182+
Poll,
183+
PollButtons,
184+
PollHeader,
177185
ReactionList,
178186
removeMessage,
179187
Reply,
@@ -203,6 +211,7 @@ export const useCreateMessagesContext = <
203211
supportedReactionsLength,
204212
myMessageTheme,
205213
targetedMessage,
214+
hasCreatePoll,
206215
],
207216
);
208217

package/src/components/Message/Message.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,9 @@ export type MessagePropsWithContext<
176176
| 'setQuotedMessageState'
177177
| 'supportedReactions'
178178
| 'updateMessage'
179+
| 'Poll'
180+
| 'PollButtons'
181+
| 'PollHeader'
179182
> &
180183
Pick<MessageOverlayContextValue<StreamChatGenerics>, 'setData'> &
181184
Pick<OverlayContextValue, 'setOverlay'> &
@@ -285,6 +288,9 @@ const MessageWithContext = <
285288
onThreadSelect,
286289
openThread,
287290
OverlayReactionList,
291+
Poll,
292+
PollButtons,
293+
PollHeader,
288294
preventPress,
289295
removeMessage,
290296
retrySendMessage,
@@ -563,7 +569,6 @@ const MessageWithContext = <
563569
});
564570

565571
const { userLanguage } = useTranslationContext();
566-
const { Poll, PollButtons, PollHeader } = useChannelContext();
567572

568573
// TODO: Can be removed in V6 and from here completely once it becomes baseline.
569574
const PollWrapper = useCallback(() => {

package/src/components/Message/MessageSimple/MessageContent.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99

1010
import { MessageTextContainer } from './MessageTextContainer';
1111

12-
import { useChannelContext, useChatContext } from '../../../contexts';
12+
import { useChatContext } from '../../../contexts';
1313
import {
1414
MessageContextValue,
1515
useMessageContext,
@@ -145,7 +145,7 @@ const MessageContentWithContext = <
145145
threadList,
146146
} = props;
147147
const { client } = useChatContext();
148-
const { Poll: PollOverride, PollButtons, PollHeader } = useChannelContext();
148+
const { Poll: PollOverride, PollButtons, PollHeader } = useMessagesContext();
149149

150150
const {
151151
theme: {

package/src/components/MessageInput/components/NativeAttachmentPicker.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import React, { useEffect, useRef } from 'react';
22
import { Animated, Easing, LayoutRectangle, Pressable, StyleSheet } from 'react-native';
33

4-
import { useChannelContext, useOwnCapabilitiesContext } from '../../../contexts';
4+
import {
5+
useChannelContext,
6+
useMessagesContext,
7+
useOwnCapabilitiesContext,
8+
} from '../../../contexts';
59
import { useMessageInputContext } from '../../../contexts/messageInputContext/MessageInputContext';
610
import { useTheme } from '../../../contexts/themeContext/ThemeContext';
711

@@ -46,7 +50,8 @@ export const NativeAttachmentPicker = ({
4650
sendMessage,
4751
takeAndUploadImage,
4852
} = useMessageInputContext();
49-
const { hasCreatePoll, threadList } = useChannelContext();
53+
const { threadList } = useChannelContext();
54+
const { hasCreatePoll } = useMessagesContext();
5055
const ownCapabilities = useOwnCapabilitiesContext();
5156

5257
const popupHeight =

package/src/contexts/channelContext/ChannelContext.tsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ export type ChannelContextValue<
5555
* When set to false, it will disable giphy command on MessageInput component.
5656
*/
5757
giphyEnabled: boolean;
58-
hasCreatePoll: boolean;
5958
/**
6059
* Hide inline date separators on channel
6160
*/
@@ -177,9 +176,6 @@ export type ChannelContextValue<
177176
* to still consider them grouped together
178177
*/
179178
maxTimeBetweenGroupedMessages?: number;
180-
Poll?: React.ComponentType;
181-
PollButtons?: React.ComponentType;
182-
PollHeader?: React.ComponentType;
183179
/**
184180
* Custom UI component for sticky header of channel.
185181
*

package/src/contexts/messagesContext/MessagesContext.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,7 @@ export type MessagesContextValue<
356356
handleRetry?: (message: MessageType<StreamChatGenerics>) => Promise<void>;
357357
/** Handler to access when a thread reply action is invoked */
358358
handleThreadReply?: (message: MessageType<StreamChatGenerics>) => Promise<void>;
359+
hasCreatePoll?: boolean;
359360
/** Handler to deal with custom memoization logic of Attachment */
360361
isAttachmentEqual?: (
361362
prevAttachment: Attachment<StreamChatGenerics>,
@@ -508,7 +509,9 @@ export type MessagesContextValue<
508509
* ```
509510
*/
510511
onPressMessage?: (payload: MessageTouchableHandlerPayload<StreamChatGenerics>) => void;
511-
512+
Poll?: React.ComponentType;
513+
PollButtons?: React.ComponentType;
514+
PollHeader?: React.ComponentType;
512515
/**
513516
* Full override of the reaction function on Message and Message Overlay
514517
*
@@ -517,7 +520,6 @@ export type MessagesContextValue<
517520
selectReaction?: (
518521
message: MessageType<StreamChatGenerics>,
519522
) => (reactionType: string) => Promise<void>;
520-
521523
targetedMessage?: string;
522524
};
523525

0 commit comments

Comments
 (0)