Skip to content

Commit ccd74f3

Browse files
Initial commit
1 parent e25f5cd commit ccd74f3

File tree

3 files changed

+50
-266
lines changed

3 files changed

+50
-266
lines changed

examples/vite/src/App.tsx

Lines changed: 33 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
useCreateChatClient,
2121
VirtualizedMessageList as MessageList,
2222
Window,
23+
WithComponents,
2324
} from 'stream-chat-react';
2425
import { createTextComposerEmojiMiddleware, EmojiPicker } from 'stream-chat-react/emojis';
2526
import { init, SearchIndex } from 'emoji-mart';
@@ -98,36 +99,38 @@ const App = () => {
9899
(error) => Promise.reject(error),
99100
);
100101
return (
101-
<Chat client={chatClient} isMessageAIGenerated={isMessageAIGenerated}>
102-
<ChatView>
103-
<ChatView.Selector />
104-
<ChatView.Channels>
105-
<ChannelList
106-
Avatar={ChannelAvatar}
107-
filters={filters}
108-
options={options}
109-
sort={sort}
110-
showChannelSearch
111-
additionalChannelSearchProps={{ searchForChannels: true }}
112-
/>
113-
<Channel emojiSearchIndex={SearchIndex} EmojiPicker={EmojiPicker}>
114-
<Window>
115-
<ChannelHeader Avatar={ChannelAvatar} />
116-
<MessageList returnAllReadData />
117-
<AIStateIndicator />
118-
<MessageInput focus audioRecordingEnabled />
119-
</Window>
120-
<Thread virtualized />
121-
</Channel>
122-
</ChatView.Channels>
123-
<ChatView.Threads>
124-
<ThreadList />
125-
<ChatView.ThreadAdapter>
126-
<Thread virtualized />
127-
</ChatView.ThreadAdapter>
128-
</ChatView.Threads>
129-
</ChatView>
130-
</Chat>
102+
<WithComponents overrides={{ emojiSearchIndex: SearchIndex, EmojiPicker }}>
103+
<Chat client={chatClient} isMessageAIGenerated={isMessageAIGenerated}>
104+
<ChatView>
105+
<ChatView.Selector />
106+
<ChatView.Channels>
107+
<ChannelList
108+
Avatar={ChannelAvatar}
109+
filters={filters}
110+
options={options}
111+
sort={sort}
112+
showChannelSearch
113+
additionalChannelSearchProps={{ searchForChannels: true }}
114+
/>
115+
<Channel>
116+
<Window>
117+
<ChannelHeader Avatar={ChannelAvatar} />
118+
<MessageList returnAllReadData />
119+
<AIStateIndicator />
120+
<MessageInput focus audioRecordingEnabled />
121+
</Window>
122+
<Thread virtualized />
123+
</Channel>
124+
</ChatView.Channels>
125+
<ChatView.Threads>
126+
<ThreadList />
127+
<ChatView.ThreadAdapter>
128+
<Thread virtualized />
129+
</ChatView.ThreadAdapter>
130+
</ChatView.Threads>
131+
</ChatView>
132+
</Chat>
133+
</WithComponents>
131134
);
132135
};
133136

src/components/Channel/Channel.tsx

Lines changed: 14 additions & 236 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ import { useIsMounted } from './hooks/useIsMounted';
4141
import type { OnMentionAction } from './hooks/useMentionsHandlers';
4242
import { useMentionsHandlers } from './hooks/useMentionsHandlers';
4343

44-
import type { LoadingErrorIndicatorProps } from '../Loading';
4544
import {
4645
LoadingErrorIndicator as DefaultLoadingErrorIndicator,
4746
LoadingChannel as DefaultLoadingIndicator,
@@ -50,16 +49,15 @@ import {
5049
import type {
5150
ChannelActionContextValue,
5251
ChannelNotifications,
53-
ComponentContextValue,
5452
MarkReadWrapperOptions,
5553
} from '../../context';
5654
import {
5755
ChannelActionProvider,
5856
ChannelStateProvider,
5957
TypingProvider,
6058
useChatContext,
59+
useComponentContext,
6160
useTranslationContext,
62-
WithComponents,
6361
} from '../../context';
6462

6563
import { CHANNEL_CONTAINER_ID } from './constants';
@@ -93,79 +91,7 @@ import {
9391
import { useSearchFocusedMessage } from '../../experimental/Search/hooks';
9492
import { WithAudioPlayback } from '../AudioPlayback';
9593

96-
type ChannelPropsForwardedToComponentContext = Pick<
97-
ComponentContextValue,
98-
| 'Attachment'
99-
| 'AttachmentPreviewList'
100-
| 'AttachmentSelector'
101-
| 'AttachmentSelectorInitiationButtonContents'
102-
| 'AudioRecorder'
103-
| 'AutocompleteSuggestionItem'
104-
| 'AutocompleteSuggestionList'
105-
| 'Avatar'
106-
| 'BaseImage'
107-
| 'CooldownTimer'
108-
| 'CustomMessageActionsList'
109-
| 'DateSeparator'
110-
| 'EditMessageInput'
111-
| 'EditMessageModal'
112-
| 'EmojiPicker'
113-
| 'emojiSearchIndex'
114-
| 'EmptyStateIndicator'
115-
| 'FileUploadIcon'
116-
| 'GiphyPreviewMessage'
117-
| 'HeaderComponent'
118-
| 'Input'
119-
| 'LinkPreviewList'
120-
| 'LoadingIndicator'
121-
| 'ShareLocationDialog'
122-
| 'Message'
123-
| 'MessageActions'
124-
| 'MessageBouncePrompt'
125-
| 'MessageBlocked'
126-
| 'MessageDeleted'
127-
| 'MessageIsThreadReplyInChannelButtonIndicator'
128-
| 'MessageListNotifications'
129-
| 'MessageListMainPanel'
130-
| 'MessageNotification'
131-
| 'MessageOptions'
132-
| 'MessageRepliesCountButton'
133-
| 'MessageStatus'
134-
| 'MessageSystem'
135-
| 'MessageTimestamp'
136-
| 'Modal'
137-
| 'ModalGallery'
138-
| 'PinIndicator'
139-
| 'PollActions'
140-
| 'PollContent'
141-
| 'PollCreationDialog'
142-
| 'PollHeader'
143-
| 'PollOptionSelector'
144-
| 'QuotedMessage'
145-
| 'QuotedMessagePreview'
146-
| 'QuotedPoll'
147-
| 'reactionOptions'
148-
| 'ReactionSelector'
149-
| 'ReactionsList'
150-
| 'ReactionsListModal'
151-
| 'ReminderNotification'
152-
| 'SendButton'
153-
| 'SendToChannelCheckbox'
154-
| 'StartRecordingAudioButton'
155-
| 'TextareaComposer'
156-
| 'ThreadHead'
157-
| 'ThreadHeader'
158-
| 'ThreadStart'
159-
| 'Timestamp'
160-
| 'TypingIndicator'
161-
| 'UnreadMessagesNotification'
162-
| 'UnreadMessagesSeparator'
163-
| 'VirtualMessage'
164-
| 'StopAIGenerationButton'
165-
| 'StreamedMessageText'
166-
>;
167-
168-
export type ChannelProps = ChannelPropsForwardedToComponentContext & {
94+
export type ChannelProps = {
16995
/** Custom handler function that runs when the active channel has unread messages and the app is running on a separate browser tab */
17096
activeUnreadHandler?: (unread: number, documentTitle: string) => void;
17197
/** Allows multiple audio players to play the audio at the same time. Disabled by default. */
@@ -213,8 +139,6 @@ export type ChannelProps = ChannelPropsForwardedToComponentContext & {
213139
* Preventing to initialize the channel on mount allows us to postpone the channel creation to a later point in time.
214140
*/
215141
initializeOnMount?: boolean;
216-
/** Custom UI component to be shown if the channel query fails, defaults to and accepts same props as: [LoadingErrorIndicator](https://github.com/GetStream/stream-chat-react/blob/master/src/components/Loading/LoadingErrorIndicator.tsx) */
217-
LoadingErrorIndicator?: React.ComponentType<LoadingErrorIndicatorProps>;
218142
/** Configuration parameter to mark the active channel as read when mounted (opened). By default, the channel is marked read on mount. */
219143
markReadOnMount?: boolean;
220144
/** Custom action handler function to run on click of an @mention in a message */
@@ -247,12 +171,9 @@ const ChannelContainer = ({
247171
};
248172

249173
const UnMemoizedChannel = (props: PropsWithChildren<ChannelProps>) => {
250-
const {
251-
channel: propsChannel,
252-
EmptyPlaceholder = null,
253-
LoadingErrorIndicator,
254-
LoadingIndicator = DefaultLoadingIndicator,
255-
} = props;
174+
const { channel: propsChannel, EmptyPlaceholder = null } = props;
175+
const { LoadingErrorIndicator, LoadingIndicator = DefaultLoadingIndicator } =
176+
useComponentContext();
256177

257178
const { channel: contextChannel, channelsQueryState } = useChatContext('Channel');
258179

@@ -300,13 +221,15 @@ const ChannelInner = (
300221
doSendMessageRequest,
301222
doUpdateMessageRequest,
302223
initializeOnMount = true,
303-
LoadingErrorIndicator = DefaultLoadingErrorIndicator,
304-
LoadingIndicator = DefaultLoadingIndicator,
305224
markReadOnMount = true,
306225
onMentionsClick,
307226
onMentionsHover,
308227
skipMessageDataMemoization,
309228
} = props;
229+
const {
230+
LoadingErrorIndicator = DefaultLoadingErrorIndicator,
231+
LoadingIndicator = DefaultLoadingIndicator,
232+
} = useComponentContext();
310233

311234
const channelQueryOptions: ChannelQueryOptions & {
312235
messages: { limit: number };
@@ -1203,149 +1126,6 @@ const ChannelInner = (
12031126
],
12041127
);
12051128

1206-
const componentContextValue: Partial<ComponentContextValue> = useMemo(
1207-
() => ({
1208-
Attachment: props.Attachment,
1209-
AttachmentPreviewList: props.AttachmentPreviewList,
1210-
AttachmentSelector: props.AttachmentSelector,
1211-
AttachmentSelectorInitiationButtonContents:
1212-
props.AttachmentSelectorInitiationButtonContents,
1213-
AudioRecorder: props.AudioRecorder,
1214-
AutocompleteSuggestionItem: props.AutocompleteSuggestionItem,
1215-
AutocompleteSuggestionList: props.AutocompleteSuggestionList,
1216-
Avatar: props.Avatar,
1217-
BaseImage: props.BaseImage,
1218-
CooldownTimer: props.CooldownTimer,
1219-
CustomMessageActionsList: props.CustomMessageActionsList,
1220-
DateSeparator: props.DateSeparator,
1221-
EditMessageInput: props.EditMessageInput,
1222-
EditMessageModal: props.EditMessageModal,
1223-
EmojiPicker: props.EmojiPicker,
1224-
emojiSearchIndex: props.emojiSearchIndex,
1225-
EmptyStateIndicator: props.EmptyStateIndicator,
1226-
FileUploadIcon: props.FileUploadIcon,
1227-
GiphyPreviewMessage: props.GiphyPreviewMessage,
1228-
HeaderComponent: props.HeaderComponent,
1229-
Input: props.Input,
1230-
LinkPreviewList: props.LinkPreviewList,
1231-
LoadingIndicator: props.LoadingIndicator,
1232-
Message: props.Message,
1233-
MessageActions: props.MessageActions,
1234-
MessageBlocked: props.MessageBlocked,
1235-
MessageBouncePrompt: props.MessageBouncePrompt,
1236-
MessageDeleted: props.MessageDeleted,
1237-
MessageIsThreadReplyInChannelButtonIndicator:
1238-
props.MessageIsThreadReplyInChannelButtonIndicator,
1239-
MessageListNotifications: props.MessageListNotifications,
1240-
MessageNotification: props.MessageNotification,
1241-
MessageOptions: props.MessageOptions,
1242-
MessageRepliesCountButton: props.MessageRepliesCountButton,
1243-
MessageStatus: props.MessageStatus,
1244-
MessageSystem: props.MessageSystem,
1245-
MessageTimestamp: props.MessageTimestamp,
1246-
Modal: props.Modal,
1247-
ModalGallery: props.ModalGallery,
1248-
PinIndicator: props.PinIndicator,
1249-
PollActions: props.PollActions,
1250-
PollContent: props.PollContent,
1251-
PollCreationDialog: props.PollCreationDialog,
1252-
PollHeader: props.PollHeader,
1253-
PollOptionSelector: props.PollOptionSelector,
1254-
QuotedMessage: props.QuotedMessage,
1255-
QuotedMessagePreview: props.QuotedMessagePreview,
1256-
QuotedPoll: props.QuotedPoll,
1257-
reactionOptions: props.reactionOptions,
1258-
ReactionSelector: props.ReactionSelector,
1259-
ReactionsList: props.ReactionsList,
1260-
ReactionsListModal: props.ReactionsListModal,
1261-
ReminderNotification: props.ReminderNotification,
1262-
SendButton: props.SendButton,
1263-
SendToChannelCheckbox: props.SendToChannelCheckbox,
1264-
ShareLocationDialog: props.ShareLocationDialog,
1265-
StartRecordingAudioButton: props.StartRecordingAudioButton,
1266-
StopAIGenerationButton: props.StopAIGenerationButton,
1267-
StreamedMessageText: props.StreamedMessageText,
1268-
TextareaComposer: props.TextareaComposer,
1269-
ThreadHead: props.ThreadHead,
1270-
ThreadHeader: props.ThreadHeader,
1271-
ThreadStart: props.ThreadStart,
1272-
Timestamp: props.Timestamp,
1273-
TypingIndicator: props.TypingIndicator,
1274-
UnreadMessagesNotification: props.UnreadMessagesNotification,
1275-
UnreadMessagesSeparator: props.UnreadMessagesSeparator,
1276-
VirtualMessage: props.VirtualMessage,
1277-
}),
1278-
[
1279-
props.Attachment,
1280-
props.AttachmentPreviewList,
1281-
props.AttachmentSelector,
1282-
props.AttachmentSelectorInitiationButtonContents,
1283-
props.AudioRecorder,
1284-
props.AutocompleteSuggestionItem,
1285-
props.AutocompleteSuggestionList,
1286-
props.Avatar,
1287-
props.BaseImage,
1288-
props.CooldownTimer,
1289-
props.CustomMessageActionsList,
1290-
props.DateSeparator,
1291-
props.EditMessageInput,
1292-
props.EditMessageModal,
1293-
props.EmojiPicker,
1294-
props.emojiSearchIndex,
1295-
props.EmptyStateIndicator,
1296-
props.FileUploadIcon,
1297-
props.GiphyPreviewMessage,
1298-
props.HeaderComponent,
1299-
props.Input,
1300-
props.LinkPreviewList,
1301-
props.LoadingIndicator,
1302-
props.Message,
1303-
props.MessageActions,
1304-
props.MessageBlocked,
1305-
props.MessageBouncePrompt,
1306-
props.MessageDeleted,
1307-
props.MessageIsThreadReplyInChannelButtonIndicator,
1308-
props.MessageListNotifications,
1309-
props.MessageNotification,
1310-
props.MessageOptions,
1311-
props.MessageRepliesCountButton,
1312-
props.MessageStatus,
1313-
props.MessageSystem,
1314-
props.MessageTimestamp,
1315-
props.Modal,
1316-
props.ModalGallery,
1317-
props.PinIndicator,
1318-
props.PollActions,
1319-
props.PollContent,
1320-
props.PollCreationDialog,
1321-
props.PollHeader,
1322-
props.PollOptionSelector,
1323-
props.QuotedMessage,
1324-
props.QuotedMessagePreview,
1325-
props.QuotedPoll,
1326-
props.reactionOptions,
1327-
props.ReactionSelector,
1328-
props.ReactionsList,
1329-
props.ReactionsListModal,
1330-
props.ReminderNotification,
1331-
props.SendButton,
1332-
props.SendToChannelCheckbox,
1333-
props.ShareLocationDialog,
1334-
props.StartRecordingAudioButton,
1335-
props.StopAIGenerationButton,
1336-
props.StreamedMessageText,
1337-
props.TextareaComposer,
1338-
props.ThreadHead,
1339-
props.ThreadHeader,
1340-
props.ThreadStart,
1341-
props.Timestamp,
1342-
props.TypingIndicator,
1343-
props.UnreadMessagesNotification,
1344-
props.UnreadMessagesSeparator,
1345-
props.VirtualMessage,
1346-
],
1347-
);
1348-
13491129
const typingContextValue = useCreateTypingContext({
13501130
typing,
13511131
});
@@ -1378,13 +1158,11 @@ const ChannelInner = (
13781158
<ChannelContainer className={windowsEmojiClass}>
13791159
<ChannelStateProvider value={channelStateContextValue}>
13801160
<ChannelActionProvider value={channelActionContextValue}>
1381-
<WithComponents overrides={componentContextValue}>
1382-
<TypingProvider value={typingContextValue}>
1383-
<WithAudioPlayback allowConcurrentPlayback={allowConcurrentAudioPlayback}>
1384-
<div className={clsx(chatContainerClass)}>{children}</div>
1385-
</WithAudioPlayback>
1386-
</TypingProvider>
1387-
</WithComponents>
1161+
<TypingProvider value={typingContextValue}>
1162+
<WithAudioPlayback allowConcurrentPlayback={allowConcurrentAudioPlayback}>
1163+
<div className={clsx(chatContainerClass)}>{children}</div>
1164+
</WithAudioPlayback>
1165+
</TypingProvider>
13881166
</ChannelActionProvider>
13891167
</ChannelStateProvider>
13901168
</ChannelContainer>

0 commit comments

Comments
 (0)