11import { HStack , Text , VisuallyHidden , VStack } from "@chakra-ui/react" ;
2+ import debounce from "lodash.debounce" ;
3+ import { useEffect , useMemo , useState } from "react" ;
24import { FormattedMessage , useIntl } from "react-intl" ;
5+ import { useStore } from "../store" ;
36import { tourElClassname } from "../tours" ;
47import InfoToolTip from "./InfoToolTip" ;
58import LedIcon from "./LedIcon" ;
69import { predictedActionDisplayWidth } from "./LiveGraphPanel" ;
7- import { useStore } from "../store" ;
810
911const PredictedAction = ( ) => {
1012 const intl = useIntl ( ) ;
1113 const predictionResult = useStore ( ( s ) => s . predictionResult ) ;
14+ const estimatedAction = predictionResult ?. detected ?. name ;
15+ const [ liveRegionEstimatedAction , setLiveRegionEstimatedAction ] = useState <
16+ string | undefined
17+ > ( estimatedAction ) ;
18+ const setLiveRegionEstimatedActionDebounced = useMemo (
19+ ( ) => debounce ( setLiveRegionEstimatedAction , 500 ) ,
20+ [ ]
21+ ) ;
22+ useEffect ( ( ) => {
23+ setLiveRegionEstimatedActionDebounced ( estimatedAction ) ;
24+ } , [ setLiveRegionEstimatedActionDebounced , estimatedAction ] ) ;
25+
1226 return (
1327 < VStack
1428 className = { tourElClassname . estimatedAction }
@@ -23,7 +37,7 @@ const PredictedAction = () => {
2337 id = "estimated-action-aria"
2438 values = { {
2539 action :
26- predictionResult ?. detected ?. name ??
40+ liveRegionEstimatedAction ??
2741 intl . formatMessage ( { id : "unknown" } ) ,
2842 } }
2943 />
@@ -52,7 +66,7 @@ const PredictedAction = () => {
5266 textAlign = "center"
5367 w = { `${ predictedActionDisplayWidth } px` }
5468 >
55- { predictionResult ?. detected ?. name ?? < FormattedMessage id = "unknown" /> }
69+ { estimatedAction ?? < FormattedMessage id = "unknown" /> }
5670 </ Text >
5771 </ VStack >
5872 ) ;
0 commit comments