File tree Expand file tree Collapse file tree 2 files changed +18
-4
lines changed
AITypingIndicatorView/hooks Expand file tree Collapse file tree 2 files changed +18
-4
lines changed Original file line number Diff line number Diff line change @@ -14,14 +14,20 @@ export const AIStates = {
1414 Thinking : 'AI_STATE_THINKING' ,
1515} ;
1616
17+ /**
18+ * A hook that returns the current state of the AI.
19+ * @param {Channel } channel - The channel for which we want to know the AI state.
20+ * @returns {{ aiState: AIState } } The current AI state for the given channel.
21+ */
1722export const useAIState = <
1823 StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics ,
1924> (
2025 channel ?: Channel < StreamChatGenerics > ,
21- ) => {
22- const { client } = useChatContext ( ) ;
26+ ) : { aiState : AIState } => {
27+ const { client } = useChatContext < StreamChatGenerics > ( ) ;
28+ const { isOnline } = useIsOnline < StreamChatGenerics > ( client ) ;
29+
2330 const [ aiState , setAiState ] = useState < AIState > ( AIStates . Idle ) ;
24- const { isOnline } = useIsOnline ( client ) ;
2531
2632 useEffect ( ( ) => {
2733 if ( ! isOnline ) {
Original file line number Diff line number Diff line change @@ -13,13 +13,21 @@ export type UseStreamingMessageProps<
1313const DEFAULT_LETTER_INTERVAL = 0 ;
1414const DEFAULT_RENDERING_LETTER_COUNT = 2 ;
1515
16+ /**
17+ * A hook that returns text in a streamed, typewriter fashion. The speed of streaming is
18+ * configurable.
19+ * @param {number } [letterInterval=0] - The timeout between each typing animation in milliseconds.
20+ * @param {number } [renderingLetterCount=2] - The number of letters to be rendered each time we update.
21+ * @param {string } text - The text that we want to render in a typewriter fashion.
22+ * @returns {{ streamedMessageText: string } } - A substring of the text property, up until we've finished rendering the typewriter animation.
23+ */
1624export const useStreamingMessage = <
1725 StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics ,
1826> ( {
1927 letterInterval = DEFAULT_LETTER_INTERVAL ,
2028 renderingLetterCount = DEFAULT_RENDERING_LETTER_COUNT ,
2129 text,
22- } : UseStreamingMessageProps < StreamChatGenerics > ) => {
30+ } : UseStreamingMessageProps < StreamChatGenerics > ) : { streamedMessageText : string } => {
2331 const [ streamedMessageText , setStreamedMessageText ] = useState < string > ( text ) ;
2432 const textCursor = useRef < number > ( text . length ) ;
2533
You can’t perform that action at this time.
0 commit comments