Skip to content

Commit 2bd176a

Browse files
committed
chore: add customizations to StreamingMessageView
1 parent 2a2622a commit 2bd176a

File tree

2 files changed

+29
-8
lines changed

2 files changed

+29
-8
lines changed

package/src/components/AITypingIndicatorView/AITypingIndicatorView.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,18 @@ import { AIStates, useAIState } from './hooks/useAIState';
99
import { useChannelContext, useTheme } from '../../contexts';
1010
import type { DefaultStreamChatGenerics } from '../../types/types';
1111

12+
export type AITypingIndicatorViewProps<
13+
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
14+
> = {
15+
channel?: Channel<StreamChatGenerics>;
16+
};
17+
1218
export const AITypingIndicatorView = <
1319
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
1420
>({
1521
channel: channelFromProps,
16-
}: {
17-
channel: Channel<StreamChatGenerics>;
18-
}) => {
19-
const { channel: channelFromContext } = useChannelContext();
22+
}: AITypingIndicatorViewProps<StreamChatGenerics>) => {
23+
const { channel: channelFromContext } = useChannelContext<StreamChatGenerics>();
2024
const channel = channelFromProps || channelFromContext;
2125
const { aiState } = useAIState(channel);
2226
// TODO: Translations

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

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,26 @@ import { MessageTextContainer, MessageTextContainerProps } from './MessageTextCo
55
import { useMessageContext } from '../../../contexts';
66
import type { DefaultStreamChatGenerics } from '../../../types/types';
77

8+
const DEFAULT_LETTER_INTERVAL = 0;
9+
const DEFAULT_RENDERING_LETTER_COUNT = 2;
10+
11+
export type StreamingMessageViewProps<
12+
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
13+
> = MessageTextContainerProps<StreamChatGenerics> & {
14+
letterInterval?: number;
15+
renderingLetterCount?: number;
16+
};
17+
818
export const StreamingMessageView = <
919
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
1020
>(
11-
props: MessageTextContainerProps<StreamChatGenerics>,
21+
props: StreamingMessageViewProps<StreamChatGenerics>,
1222
) => {
23+
const {
24+
letterInterval = DEFAULT_LETTER_INTERVAL,
25+
renderingLetterCount = DEFAULT_RENDERING_LETTER_COUNT,
26+
...restProps
27+
} = props;
1328
const { message } = useMessageContext<StreamChatGenerics>();
1429
const { text = '' } = message;
1530
const [streamedMessageText, setStreamedMessageText] = useState<string>(text);
@@ -22,18 +37,20 @@ export const StreamingMessageView = <
2237
clearInterval(interval);
2338
}
2439
// TODO: make this configurable maybe
25-
const newCursorValue = textCursor.current + 2;
40+
const newCursorValue = textCursor.current + renderingLetterCount;
2641
const newText = text.substring(0, newCursorValue);
2742
textCursor.current += newText.length - textCursor.current;
2843
setStreamedMessageText(newText);
29-
}, 0);
44+
}, letterInterval);
3045

3146
return () => {
3247
clearInterval(interval);
3348
};
3449
}, [text]);
3550

36-
return <MessageTextContainer message={{ ...message, text: streamedMessageText }} {...props} />;
51+
return (
52+
<MessageTextContainer message={{ ...message, text: streamedMessageText }} {...restProps} />
53+
);
3754
};
3855

3956
StreamingMessageView.displayName = 'StreamingMessageView{messageSimple{content}}';

0 commit comments

Comments
 (0)