| import React, { useEffect, useRef, useState } from 'react' | import React, { useEffect, useRef, useState } from 'react' | ||||
| import { useTranslation } from 'react-i18next' | import { useTranslation } from 'react-i18next' | ||||
| import { useChatContext } from '../chat/chat/context' | |||||
| const hasEndThink = (children: any): boolean => { | const hasEndThink = (children: any): boolean => { | ||||
| if (typeof children === 'string') | if (typeof children === 'string') | ||||
| } | } | ||||
| const useThinkTimer = (children: any) => { | const useThinkTimer = (children: any) => { | ||||
| const { isResponding } = useChatContext() | |||||
| const [startTime] = useState(Date.now()) | const [startTime] = useState(Date.now()) | ||||
| const [elapsedTime, setElapsedTime] = useState(0) | const [elapsedTime, setElapsedTime] = useState(0) | ||||
| const [isComplete, setIsComplete] = useState(false) | const [isComplete, setIsComplete] = useState(false) | ||||
| }, [startTime, isComplete]) | }, [startTime, isComplete]) | ||||
| useEffect(() => { | useEffect(() => { | ||||
| if (hasEndThink(children)) | |||||
| if (hasEndThink(children) || !isResponding) | |||||
| setIsComplete(true) | setIsComplete(true) | ||||
| }, [children]) | |||||
| }, [children, isResponding]) | |||||
| return { elapsedTime, isComplete } | return { elapsedTime, isComplete } | ||||
| } | } |