Skip to content

Commit

Permalink
chore: add override for stop streaming button
Browse files Browse the repository at this point in the history
  • Loading branch information
isekovanic committed Dec 3, 2024
1 parent abe10de commit 366fbd1
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 5 deletions.
14 changes: 13 additions & 1 deletion package/src/components/Channel/Channel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ import { MoreOptionsButton as MoreOptionsButtonDefault } from '../MessageInput/M
import { SendButton as SendButtonDefault } from '../MessageInput/SendButton';
import { SendMessageDisallowedIndicator as SendMessageDisallowedIndicatorDefault } from '../MessageInput/SendMessageDisallowedIndicator';
import { ShowThreadMessageInChannelButton as ShowThreadMessageInChannelButtonDefault } from '../MessageInput/ShowThreadMessageInChannelButton';
import { StopMessageStreamingButton as DefaultStopMessageStreamingButton } from '../MessageInput/StopMessageStreamingButton';
import { UploadProgressIndicator as UploadProgressIndicatorDefault } from '../MessageInput/UploadProgressIndicator';
import { DateHeader as DateHeaderDefault } from '../MessageList/DateHeader';
import type { MessageType } from '../MessageList/hooks/useMessageList';
Expand Down Expand Up @@ -443,7 +444,12 @@ export type ChannelPropsWithContext<
* Tells if channel is rendering a thread list
*/
threadList?: boolean;
} & Partial<Pick<InputMessageInputContextValue, 'openPollCreationDialog' | 'CreatePollContent'>>;
} & Partial<
Pick<
InputMessageInputContextValue,
'openPollCreationDialog' | 'CreatePollContent' | 'StopMessageStreamingButton'
>
>;

const ChannelWithContext = <
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
Expand Down Expand Up @@ -635,6 +641,7 @@ const ChannelWithContext = <
StartAudioRecordingButton = AudioRecordingButtonDefault,
stateUpdateThrottleInterval = defaultThrottleInterval,
StickyHeader = StickyHeaderDefault,
StopMessageStreamingButton: StopMessageStreamingButtonOverride,
StreamingMessageView = DefaultStreamingMessageView,
supportedReactions = reactionData,
t,
Expand All @@ -652,6 +659,10 @@ const ChannelWithContext = <
} = props;

const { thread: threadProps, threadInstance } = threadFromProps;
const StopMessageStreamingButton =
StopMessageStreamingButtonOverride === undefined
? DefaultStopMessageStreamingButton
: StopMessageStreamingButtonOverride;

const {
theme: {
Expand Down Expand Up @@ -2254,6 +2265,7 @@ const ChannelWithContext = <
setQuotedMessageState,
ShowThreadMessageInChannelButton,
StartAudioRecordingButton,
StopMessageStreamingButton,
UploadProgressIndicator,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export const useCreateInputMessageInputContext = <
showPollCreationDialog,
ShowThreadMessageInChannelButton,
StartAudioRecordingButton,
StopMessageStreamingButton,
UploadProgressIndicator,
}: InputMessageInputContextValue<StreamChatGenerics> & {
/**
Expand Down Expand Up @@ -133,6 +134,7 @@ export const useCreateInputMessageInputContext = <
showPollCreationDialog,
ShowThreadMessageInChannelButton,
StartAudioRecordingButton,
StopMessageStreamingButton,
UploadProgressIndicator,
}),
// eslint-disable-next-line react-hooks/exhaustive-deps
Expand Down
9 changes: 6 additions & 3 deletions package/src/components/MessageInput/MessageInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ import type { UserResponse } from 'stream-chat';
import { useAudioController } from './hooks/useAudioController';
import { useCountdown } from './hooks/useCountdown';

import { StopMessageStreamingButton } from './StopMessageStreamingButton';

import { ChatContextValue, useChatContext, useOwnCapabilitiesContext } from '../../contexts';
import {
AttachmentPickerContextValue,
Expand Down Expand Up @@ -162,6 +160,7 @@ type MessageInputPropsWithContext<
| 'showPollCreationDialog'
| 'sendMessage'
| 'CreatePollContent'
| 'StopMessageStreamingButton'
> &
Pick<MessagesContextValue<StreamChatGenerics>, 'Reply'> &
Pick<
Expand Down Expand Up @@ -231,6 +230,7 @@ const MessageInputWithContext = <
showPollCreationDialog,
ShowThreadMessageInChannelButton,
StartAudioRecordingButton,
StopMessageStreamingButton,
suggestions,
text,
thread,
Expand Down Expand Up @@ -734,7 +734,8 @@ const MessageInputWithContext = <
const { aiState } = useAIState(channel);

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

return (
<>
Expand Down Expand Up @@ -1156,6 +1157,7 @@ export const MessageInput = <
showPollCreationDialog,
ShowThreadMessageInChannelButton,
StartAudioRecordingButton,
StopMessageStreamingButton,
text,
uploadNewFile,
uploadNewImage,
Expand Down Expand Up @@ -1245,6 +1247,7 @@ export const MessageInput = <
showPollCreationDialog,
ShowThreadMessageInChannelButton,
StartAudioRecordingButton,
StopMessageStreamingButton,
suggestions,
t,
text,
Expand Down
1 change: 1 addition & 0 deletions package/src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ export * from './MessageInput/InputButtons';
export * from './MessageInput/MessageInput';
export * from './MessageInput/MoreOptionsButton';
export * from './MessageInput/SendButton';
export * from './MessageInput/StopMessageStreamingButton';
export * from './MessageInput/ShowThreadMessageInChannelButton';
export * from './MessageInput/UploadProgressIndicator';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import { useMessageDetailsForState } from './hooks/useMessageDetailsForState';

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

import { PollContentProps } from '../../components';
import { PollContentProps, StopMessageStreamingButtonProps } from '../../components';
import { AudioAttachmentProps } from '../../components/Attachment/AudioAttachment';
import { parseLinksFromText } from '../../components/Message/MessageSimple/utils/parseLinks';
import type { AttachButtonProps } from '../../components/MessageInput/AttachButton';
Expand Down Expand Up @@ -388,6 +388,7 @@ export type InputMessageInputContextValue<
* 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)
*/
StartAudioRecordingButton: React.ComponentType<AudioRecordingButtonProps<StreamChatGenerics>>;
StopMessageStreamingButton: React.ComponentType<StopMessageStreamingButtonProps>;
/**
* Custom UI component to render upload progress indicator on attachment preview.
*
Expand Down Expand Up @@ -590,7 +591,9 @@ export const MessageInputProvider = <
editing,
initialValue,
openPollCreationDialog: openPollCreationDialogFromContext,
StopMessageStreamingButton,
} = value;

const {
fileUploads,
imageUploads,
Expand Down Expand Up @@ -1482,6 +1485,7 @@ export const MessageInputProvider = <
openPollCreationDialog,
sendMessage, // overriding the originally passed in sendMessage
showPollCreationDialog,
StopMessageStreamingButton,
});
return (
<MessageInputContext.Provider
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ export const useCreateMessageInputContext = <
showPollCreationDialog,
ShowThreadMessageInChannelButton,
StartAudioRecordingButton,
StopMessageStreamingButton,
takeAndUploadImage,
text,
thread,
Expand Down Expand Up @@ -225,6 +226,7 @@ export const useCreateMessageInputContext = <
showPollCreationDialog,
ShowThreadMessageInChannelButton,
StartAudioRecordingButton,
StopMessageStreamingButton,
takeAndUploadImage,
text,
toggleAttachmentPicker,
Expand Down

0 comments on commit 366fbd1

Please sign in to comment.