Skip to content

Commit 4891976

Browse files
committed
fix: cover background mode case
1 parent 911ea9a commit 4891976

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

package/src/components/AITypingIndicatorView/hooks/useAIState.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ import { useEffect, useState } from 'react';
22

33
import { Channel, Event } from 'stream-chat';
44

5+
import { useChatContext } from '../../../contexts';
56
import type { DefaultStreamChatGenerics } from '../../../types/types';
7+
import { useIsOnline } from '../../Chat/hooks/useIsOnline';
68

79
export 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) {

0 commit comments

Comments
 (0)