Skip to content

Commit 4c84723

Browse files
committed
fix: stop ai generation button PR remarks
1 parent e7468a0 commit 4c84723

File tree

5 files changed

+27
-21
lines changed

5 files changed

+27
-21
lines changed

src/components/Channel/Channel.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ type ChannelPropsForwardedToComponentContext<
161161
| 'UnreadMessagesNotification'
162162
| 'UnreadMessagesSeparator'
163163
| 'VirtualMessage'
164+
| 'StopAIGenerationButton'
164165
>;
165166

166167
const isUserResponseArray = <
@@ -1273,6 +1274,7 @@ const ChannelInner = <
12731274
ReactionsList: props.ReactionsList,
12741275
SendButton: props.SendButton,
12751276
StartRecordingAudioButton: props.StartRecordingAudioButton,
1277+
StopAIGenerationButton: props.StopAIGenerationButton,
12761278
ThreadHead: props.ThreadHead,
12771279
ThreadHeader: props.ThreadHeader,
12781280
ThreadStart: props.ThreadStart,
@@ -1339,6 +1341,7 @@ const ChannelInner = <
13391341
props.UnreadMessagesNotification,
13401342
props.UnreadMessagesSeparator,
13411343
props.VirtualMessage,
1344+
props.StopAIGenerationButton,
13421345
props.emojiSearchIndex,
13431346
props.reactionOptions,
13441347
],

src/components/MessageInput/MessageInputFlat.tsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
import { AttachmentPreviewList as DefaultAttachmentPreviewList } from './AttachmentPreviewList';
1010
import { CooldownTimer as DefaultCooldownTimer } from './CooldownTimer';
1111
import { SendButton as DefaultSendButton } from './SendButton';
12-
import { StopGeneratingButton as DefaultStopGeneratingButton } from './StopGeneratingButton';
12+
import { StopAIGenerationButton as DefaultStopAIGenerationButton } from './StopAIGenerationButton';
1313
import {
1414
AudioRecorder as DefaultAudioRecorder,
1515
RecordingPermissionDeniedNotification as DefaultRecordingPermissionDeniedNotification,
@@ -68,9 +68,13 @@ export const MessageInputFlat = <
6868
RecordingPermissionDeniedNotification = DefaultRecordingPermissionDeniedNotification,
6969
SendButton = DefaultSendButton,
7070
StartRecordingAudioButton = DefaultStartRecordingAudioButton,
71-
StopGeneratingButton = DefaultStopGeneratingButton,
71+
StopAIGenerationButton: StopAIGenerationButtonOverride,
7272
EmojiPicker,
7373
} = useComponentContext<StreamChatGenerics>('MessageInputFlat');
74+
const StopAIGenerationButton =
75+
StopAIGenerationButtonOverride === undefined
76+
? DefaultStopAIGenerationButton
77+
: StopAIGenerationButtonOverride;
7478
const {
7579
acceptedFiles = [],
7680
multipleUploads,
@@ -142,7 +146,8 @@ export const MessageInputFlat = <
142146
const recordingEnabled = !!(recordingController.recorder && navigator.mediaDevices); // account for requirement on iOS as per this bug report: https://bugs.webkit.org/show_bug.cgi?id=252303
143147
const isRecording = !!recordingController.recordingState;
144148

145-
const shouldDisplayStopAIGeneration = [AIStates.Thinking, AIStates.Generating].includes(aiState);
149+
const shouldDisplayStopAIGeneration =
150+
[AIStates.Thinking, AIStates.Generating].includes(aiState) && !!StopAIGenerationButton;
146151

147152
return (
148153
<>
@@ -186,7 +191,7 @@ export const MessageInputFlat = <
186191
</div>
187192
</div>
188193
{shouldDisplayStopAIGeneration ? (
189-
<StopGeneratingButton onClick={stopGenerating} />
194+
<StopAIGenerationButton onClick={stopGenerating} />
190195
) : (
191196
!hideSendButton && (
192197
<>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import React from 'react';
2+
3+
export type StopAIGenerationButtonProps = React.ComponentProps<'button'>;
4+
5+
export const StopAIGenerationButton = ({ onClick, ...restProps }: StopAIGenerationButtonProps) => (
6+
<button
7+
aria-label='aria/Stop'
8+
className='str-chat__stop-generating-button'
9+
data-testid='stop-ai-generation-button'
10+
onClick={onClick}
11+
{...restProps}
12+
/>
13+
);

src/components/MessageInput/StopGeneratingButton.tsx

Lines changed: 0 additions & 15 deletions
This file was deleted.

src/context/ComponentContext.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ import type {
5454
PropsWithChildrenOnly,
5555
UnknownType,
5656
} from '../types/types';
57-
import { StopGeneratingButtonProps } from '../components/MessageInput/StopGeneratingButton';
57+
import type { StopAIGenerationButtonProps } from '../components/MessageInput/StopAIGenerationButton';
5858

5959
export type ComponentContextValue<
6060
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
@@ -165,7 +165,7 @@ export type ComponentContextValue<
165165
SendButton?: React.ComponentType<SendButtonProps<StreamChatGenerics>>;
166166
/** Custom UI component button for initiating audio recording, defaults to and accepts same props as: [StartRecordingAudioButton](https://github.com/GetStream/stream-chat-react/blob/master/src/components/MediaRecorder/AudioRecorder/AudioRecordingButtons.tsx) */
167167
StartRecordingAudioButton?: React.ComponentType<StartRecordingAudioButtonProps>;
168-
StopGeneratingButton?: React.ComponentType<StopGeneratingButtonProps>;
168+
StopAIGenerationButton?: React.ComponentType<StopAIGenerationButtonProps> | null;
169169
/** Custom UI component that displays thread's parent or other message at the top of the `MessageList`, defaults to and accepts same props as [MessageSimple](https://github.com/GetStream/stream-chat-react/blob/master/src/components/Message/MessageSimple.tsx) */
170170
ThreadHead?: React.ComponentType<MessageProps<StreamChatGenerics>>;
171171
/** Custom UI component to display the header of a `Thread`, defaults to and accepts same props as: [DefaultThreadHeader](https://github.com/GetStream/stream-chat-react/blob/master/src/components/Thread/Thread.tsx) */

0 commit comments

Comments
 (0)