1- import React , { useState , useEffect } from "react"
1+ import React , { useState , useEffect , useMemo } from "react"
22import { cn } from "@src/lib/utils"
33import { vscode } from "@src/utils/vscode"
4-
5- interface IndexingStatus {
6- systemStatus : string
7- message ?: string
8- processedItems : number
9- totalItems : number
10- currentItemUnit ?: string
11- }
12-
13- interface IndexingStatusUpdateMessage {
14- type : "indexingStatusUpdate"
15- values : IndexingStatus
16- }
4+ import { useAppTranslation } from "@/i18n/TranslationContext"
5+ import { useTooltip } from "@/hooks/useTooltip"
6+ import type { IndexingStatus , IndexingStatusUpdateMessage } from "@roo/ExtensionMessage"
177
188interface IndexingStatusDotProps {
199 onNavigateToSettings ?: ( ) => void
2010 className ?: string
2111}
2212
2313export const IndexingStatusDot : React . FC < IndexingStatusDotProps > = ( { onNavigateToSettings, className } ) => {
14+ const { t } = useAppTranslation ( )
15+ const { showTooltip, handleMouseEnter, handleMouseLeave, cleanup } = useTooltip ( { delay : 300 } )
16+
2417 const [ indexingStatus , setIndexingStatus ] = useState < IndexingStatus > ( {
2518 systemStatus : "Standby" ,
2619 processedItems : 0 ,
2720 totalItems : 0 ,
2821 currentItemUnit : "items" ,
2922 } )
30- const [ showTooltip , setShowTooltip ] = useState ( false )
31- const [ tooltipTimeout , setTooltipTimeout ] = useState < NodeJS . Timeout | null > ( null )
3223
3324 useEffect ( ( ) => {
3425 // Request initial indexing status
@@ -46,44 +37,35 @@ export const IndexingStatusDot: React.FC<IndexingStatusDotProps> = ({ onNavigate
4637
4738 return ( ) => {
4839 window . removeEventListener ( "message" , handleMessage )
49- if ( tooltipTimeout ) clearTimeout ( tooltipTimeout )
40+ cleanup ( )
5041 }
51- } , [ tooltipTimeout ] )
42+ } , [ cleanup ] )
5243
53- // Calculate progress percentage
54- const progressPercentage =
55- indexingStatus . totalItems > 0
56- ? Math . round ( ( indexingStatus . processedItems / indexingStatus . totalItems ) * 100 )
57- : 0
44+ // Calculate progress percentage with memoization
45+ const progressPercentage = useMemo (
46+ ( ) =>
47+ indexingStatus . totalItems > 0
48+ ? Math . round ( ( indexingStatus . processedItems / indexingStatus . totalItems ) * 100 )
49+ : 0 ,
50+ [ indexingStatus . processedItems , indexingStatus . totalItems ] ,
51+ )
5852
59- // Get tooltip text
53+ // Get tooltip text with internationalization
6054 const getTooltipText = ( ) => {
6155 switch ( indexingStatus . systemStatus ) {
6256 case "Standby" :
63- return "Index ready"
57+ return t ( "chat:indexingStatus. ready")
6458 case "Indexing" :
65- return `Indexing ${ progressPercentage } %`
59+ return t ( "chat:indexingStatus.indexing" , { percentage : progressPercentage } )
6660 case "Indexed" :
67- return "Indexed"
61+ return t ( "chat:indexingStatus.indexed" )
6862 case "Error" :
69- return "Index error"
63+ return t ( "chat:indexingStatus. error")
7064 default :
71- return "Index status"
65+ return t ( "chat:indexingStatus. status")
7266 }
7367 }
7468
75- // Handle mouse events for tooltip
76- const handleMouseEnter = ( ) => {
77- if ( tooltipTimeout ) clearTimeout ( tooltipTimeout )
78- const timeout = setTimeout ( ( ) => setShowTooltip ( true ) , 300 ) // 300ms delay
79- setTooltipTimeout ( timeout )
80- }
81-
82- const handleMouseLeave = ( ) => {
83- if ( tooltipTimeout ) clearTimeout ( tooltipTimeout )
84- setShowTooltip ( false )
85- }
86-
8769 // Navigate to settings when clicked
8870 const handleClick = ( ) => {
8971 if ( onNavigateToSettings ) {
0 commit comments