@@ -5,15 +5,7 @@ import { getCodebuffClient } from '../utils/codebuff-client'
55
66import type { ChatTheme } from '../utils/theme-system'
77
8- export const StatusIndicator = ( {
9- isProcessing,
10- theme,
11- clipboardMessage,
12- } : {
13- isProcessing : boolean
14- theme : ChatTheme
15- clipboardMessage ?: string | null
16- } ) => {
8+ const useConnectionStatus = ( ) => {
179 const [ isConnected , setIsConnected ] = useState < boolean | null > ( null )
1810
1911 useEffect ( ( ) => {
@@ -39,6 +31,20 @@ export const StatusIndicator = ({
3931 return ( ) => clearInterval ( interval )
4032 } , [ ] )
4133
34+ return isConnected
35+ }
36+
37+ export const StatusIndicator = ( {
38+ isProcessing,
39+ theme,
40+ clipboardMessage,
41+ } : {
42+ isProcessing : boolean
43+ theme : ChatTheme
44+ clipboardMessage ?: string | null
45+ } ) => {
46+ const isConnected = useConnectionStatus ( )
47+
4248 if ( clipboardMessage ) {
4349 return < span fg = { theme . statusAccent } > { clipboardMessage } </ span >
4450 }
@@ -70,30 +76,6 @@ export const useHasStatus = (
7076 isProcessing : boolean ,
7177 clipboardMessage ?: string | null ,
7278) : boolean => {
73- const [ isConnected , setIsConnected ] = useState < boolean | null > ( null )
74-
75- useEffect ( ( ) => {
76- const checkConnection = async ( ) => {
77- const client = getCodebuffClient ( )
78- if ( ! client ) {
79- setIsConnected ( false )
80- return
81- }
82-
83- try {
84- const connected = await client . checkConnection ( )
85- setIsConnected ( connected )
86- } catch ( error ) {
87- setIsConnected ( false )
88- }
89- }
90-
91- checkConnection ( )
92-
93- const interval = setInterval ( checkConnection , 30000 )
94-
95- return ( ) => clearInterval ( interval )
96- } , [ ] )
97-
79+ const isConnected = useConnectionStatus ( )
9880 return isConnected === false || isProcessing || ! ! clipboardMessage
9981}
0 commit comments