File tree Expand file tree Collapse file tree 1 file changed +10
-0
lines changed
package/src/components/AITypingIndicatorView/hooks Expand file tree Collapse file tree 1 file changed +10
-0
lines changed Original file line number Diff line number Diff line change @@ -2,7 +2,9 @@ import { useEffect, useState } from 'react';
22
33import { Channel , Event } from 'stream-chat' ;
44
5+ import { useChatContext } from '../../../contexts' ;
56import type { DefaultStreamChatGenerics } from '../../../types/types' ;
7+ import { useIsOnline } from '../../Chat/hooks/useIsOnline' ;
68
79export type AIStateType =
810 | 'AI_STATE_ERROR'
@@ -25,7 +27,15 @@ export const useAIState = <
2527> (
2628 channel ?: Channel < StreamChatGenerics > ,
2729) => {
30+ const { client } = useChatContext ( ) ;
2831 const [ aiState , setAiState ] = useState < AIStateType > ( AIStates . Idle ) ;
32+ const { isOnline } = useIsOnline ( client ) ;
33+
34+ useEffect ( ( ) => {
35+ if ( ! isOnline ) {
36+ setAiState ( AIStates . Idle ) ;
37+ }
38+ } , [ isOnline ] ) ;
2939
3040 useEffect ( ( ) => {
3141 if ( ! channel ) {
You can’t perform that action at this time.
0 commit comments