Skip to content

Commit 366fbd1

Browse files
committed
chore: add override for stop streaming button
1 parent abe10de commit 366fbd1

File tree

6 files changed

+29
-5
lines changed

6 files changed

+29
-5
lines changed

package/src/components/Channel/Channel.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ import { MoreOptionsButton as MoreOptionsButtonDefault } from '../MessageInput/M
162162
import { SendButton as SendButtonDefault } from '../MessageInput/SendButton';
163163
import { SendMessageDisallowedIndicator as SendMessageDisallowedIndicatorDefault } from '../MessageInput/SendMessageDisallowedIndicator';
164164
import { ShowThreadMessageInChannelButton as ShowThreadMessageInChannelButtonDefault } from '../MessageInput/ShowThreadMessageInChannelButton';
165+
import { StopMessageStreamingButton as DefaultStopMessageStreamingButton } from '../MessageInput/StopMessageStreamingButton';
165166
import { UploadProgressIndicator as UploadProgressIndicatorDefault } from '../MessageInput/UploadProgressIndicator';
166167
import { DateHeader as DateHeaderDefault } from '../MessageList/DateHeader';
167168
import type { MessageType } from '../MessageList/hooks/useMessageList';
@@ -443,7 +444,12 @@ export type ChannelPropsWithContext<
443444
* Tells if channel is rendering a thread list
444445
*/
445446
threadList?: boolean;
446-
} & Partial<Pick<InputMessageInputContextValue, 'openPollCreationDialog' | 'CreatePollContent'>>;
447+
} & Partial<
448+
Pick<
449+
InputMessageInputContextValue,
450+
'openPollCreationDialog' | 'CreatePollContent' | 'StopMessageStreamingButton'
451+
>
452+
>;
447453

448454
const ChannelWithContext = <
449455
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
@@ -635,6 +641,7 @@ const ChannelWithContext = <
635641
StartAudioRecordingButton = AudioRecordingButtonDefault,
636642
stateUpdateThrottleInterval = defaultThrottleInterval,
637643
StickyHeader = StickyHeaderDefault,
644+
StopMessageStreamingButton: StopMessageStreamingButtonOverride,
638645
StreamingMessageView = DefaultStreamingMessageView,
639646
supportedReactions = reactionData,
640647
t,
@@ -652,6 +659,10 @@ const ChannelWithContext = <
652659
} = props;
653660

654661
const { thread: threadProps, threadInstance } = threadFromProps;
662+
const StopMessageStreamingButton =
663+
StopMessageStreamingButtonOverride === undefined
664+
? DefaultStopMessageStreamingButton
665+
: StopMessageStreamingButtonOverride;
655666

656667
const {
657668
theme: {
@@ -2254,6 +2265,7 @@ const ChannelWithContext = <
22542265
setQuotedMessageState,
22552266
ShowThreadMessageInChannelButton,
22562267
StartAudioRecordingButton,
2268+
StopMessageStreamingButton,
22572269
UploadProgressIndicator,
22582270
});
22592271

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ export const useCreateInputMessageInputContext = <
6464
showPollCreationDialog,
6565
ShowThreadMessageInChannelButton,
6666
StartAudioRecordingButton,
67+
StopMessageStreamingButton,
6768
UploadProgressIndicator,
6869
}: InputMessageInputContextValue<StreamChatGenerics> & {
6970
/**
@@ -133,6 +134,7 @@ export const useCreateInputMessageInputContext = <
133134
showPollCreationDialog,
134135
ShowThreadMessageInChannelButton,
135136
StartAudioRecordingButton,
137+
StopMessageStreamingButton,
136138
UploadProgressIndicator,
137139
}),
138140
// eslint-disable-next-line react-hooks/exhaustive-deps

package/src/components/MessageInput/MessageInput.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ import type { UserResponse } from 'stream-chat';
2828
import { useAudioController } from './hooks/useAudioController';
2929
import { useCountdown } from './hooks/useCountdown';
3030

31-
import { StopMessageStreamingButton } from './StopMessageStreamingButton';
32-
3331
import { ChatContextValue, useChatContext, useOwnCapabilitiesContext } from '../../contexts';
3432
import {
3533
AttachmentPickerContextValue,
@@ -162,6 +160,7 @@ type MessageInputPropsWithContext<
162160
| 'showPollCreationDialog'
163161
| 'sendMessage'
164162
| 'CreatePollContent'
163+
| 'StopMessageStreamingButton'
165164
> &
166165
Pick<MessagesContextValue<StreamChatGenerics>, 'Reply'> &
167166
Pick<
@@ -231,6 +230,7 @@ const MessageInputWithContext = <
231230
showPollCreationDialog,
232231
ShowThreadMessageInChannelButton,
233232
StartAudioRecordingButton,
233+
StopMessageStreamingButton,
234234
suggestions,
235235
text,
236236
thread,
@@ -734,7 +734,8 @@ const MessageInputWithContext = <
734734
const { aiState } = useAIState(channel);
735735

736736
const stopGenerating = useCallback(() => channel?.stopAIResponse(), [channel]);
737-
const shouldDisplayStopAIGeneration = [AIStates.Thinking, AIStates.Generating].includes(aiState);
737+
const shouldDisplayStopAIGeneration =
738+
[AIStates.Thinking, AIStates.Generating].includes(aiState) && !!StopMessageStreamingButton;
738739

739740
return (
740741
<>
@@ -1156,6 +1157,7 @@ export const MessageInput = <
11561157
showPollCreationDialog,
11571158
ShowThreadMessageInChannelButton,
11581159
StartAudioRecordingButton,
1160+
StopMessageStreamingButton,
11591161
text,
11601162
uploadNewFile,
11611163
uploadNewImage,
@@ -1245,6 +1247,7 @@ export const MessageInput = <
12451247
showPollCreationDialog,
12461248
ShowThreadMessageInChannelButton,
12471249
StartAudioRecordingButton,
1250+
StopMessageStreamingButton,
12481251
suggestions,
12491252
t,
12501253
text,

package/src/components/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ export * from './MessageInput/InputButtons';
134134
export * from './MessageInput/MessageInput';
135135
export * from './MessageInput/MoreOptionsButton';
136136
export * from './MessageInput/SendButton';
137+
export * from './MessageInput/StopMessageStreamingButton';
137138
export * from './MessageInput/ShowThreadMessageInChannelButton';
138139
export * from './MessageInput/UploadProgressIndicator';
139140

package/src/contexts/messageInputContext/MessageInputContext.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import { useMessageDetailsForState } from './hooks/useMessageDetailsForState';
2929

3030
import { isUploadAllowed, MAX_FILE_SIZE_TO_UPLOAD, prettifyFileSize } from './utils/utils';
3131

32-
import { PollContentProps } from '../../components';
32+
import { PollContentProps, StopMessageStreamingButtonProps } from '../../components';
3333
import { AudioAttachmentProps } from '../../components/Attachment/AudioAttachment';
3434
import { parseLinksFromText } from '../../components/Message/MessageSimple/utils/parseLinks';
3535
import type { AttachButtonProps } from '../../components/MessageInput/AttachButton';
@@ -388,6 +388,7 @@ export type InputMessageInputContextValue<
388388
* Defaults to and accepts same props as: [AudioRecordingButton](https://github.com/GetStream/stream-chat-react-native/blob/main/package/src/components/MessageInput/components/AudioRecorder/AudioRecordingButton.tsx)
389389
*/
390390
StartAudioRecordingButton: React.ComponentType<AudioRecordingButtonProps<StreamChatGenerics>>;
391+
StopMessageStreamingButton: React.ComponentType<StopMessageStreamingButtonProps>;
391392
/**
392393
* Custom UI component to render upload progress indicator on attachment preview.
393394
*
@@ -590,7 +591,9 @@ export const MessageInputProvider = <
590591
editing,
591592
initialValue,
592593
openPollCreationDialog: openPollCreationDialogFromContext,
594+
StopMessageStreamingButton,
593595
} = value;
596+
594597
const {
595598
fileUploads,
596599
imageUploads,
@@ -1482,6 +1485,7 @@ export const MessageInputProvider = <
14821485
openPollCreationDialog,
14831486
sendMessage, // overriding the originally passed in sendMessage
14841487
showPollCreationDialog,
1488+
StopMessageStreamingButton,
14851489
});
14861490
return (
14871491
<MessageInputContext.Provider

package/src/contexts/messageInputContext/hooks/useCreateMessageInputContext.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ export const useCreateMessageInputContext = <
103103
showPollCreationDialog,
104104
ShowThreadMessageInChannelButton,
105105
StartAudioRecordingButton,
106+
StopMessageStreamingButton,
106107
takeAndUploadImage,
107108
text,
108109
thread,
@@ -225,6 +226,7 @@ export const useCreateMessageInputContext = <
225226
showPollCreationDialog,
226227
ShowThreadMessageInChannelButton,
227228
StartAudioRecordingButton,
229+
StopMessageStreamingButton,
228230
takeAndUploadImage,
229231
text,
230232
toggleAttachmentPicker,

0 commit comments

Comments
 (0)