11import React from 'react' ;
22import type { LocalizedString } from 'typesafe-i18n' ;
33
4- import { useAsyncState } from '../../hooks/useAsyncState' ;
54import { useBooleanState } from '../../hooks/useBooleanState' ;
65import { useCachedState } from '../../hooks/useCachedState' ;
76import { useId } from '../../hooks/useId' ;
@@ -140,26 +139,38 @@ export function Tree<
140139 } ;
141140
142141 // Add a cookie or local storage (browser storage), if not busy than never call this again
143- const [ treePreloading ] = useAsyncState (
144- React . useCallback (
145- async ( ) =>
146- ajax < PreloadProgress > ( '/setup_tool/preload_tree_status/' , {
147- method : 'GET' ,
148- headers : { Accept : 'application/json' } ,
149- errorMode : 'silent' ,
142+ const [ treePreloading , setTreePreloading ] = React . useState <
143+ PreloadProgress | undefined
144+ > ( undefined ) ;
145+
146+ React . useEffect ( ( ) => {
147+ let intervalId : NodeJS . Timeout ;
148+
149+ const fetchTreeProgress = ( ) => {
150+ ajax < PreloadProgress > ( '/setup_tool/preload_tree_status/' , {
151+ method : 'GET' ,
152+ headers : { Accept : 'application/json' } ,
153+ errorMode : 'silent' ,
154+ } )
155+ . then ( ( { data } ) => {
156+ console . log ( data , rows . length ) ;
157+ setTreePreloading ( data ) ;
158+
159+ if ( ! data ?. busy && intervalId ) {
160+ clearInterval ( intervalId ) ;
161+ }
150162 } )
151- . then ( ( { data } ) => {
152- console . log ( data ) ;
153- return data ;
154- } )
155- . catch ( ( error ) => {
156- console . error ( 'Failed to fetch setup progress:' , error ) ;
157- return undefined ;
158- } ) ,
159- [ ]
160- ) ,
161- true
162- ) ;
163+ . catch ( ( error ) => {
164+ console . error ( 'Failed to fetch setup progress:' , error ) ;
165+ } ) ;
166+ } ;
167+
168+ fetchTreeProgress ( ) ;
169+
170+ intervalId = setInterval ( fetchTreeProgress , 5000 ) ;
171+
172+ return ( ) => clearInterval ( intervalId ) ;
173+ } , [ ] ) ;
163174
164175 return (
165176 < div
@@ -171,7 +182,6 @@ export function Tree<
171182 ${ highContrast ? 'border dark:border-white' : 'bg-gradient-to-bl' }
172183 ` }
173184 role = "none table"
174- // First role is for screen readers. Second is for styling
175185 style = {
176186 {
177187 '--cols' : treeDefinitionItems . length ,
@@ -180,11 +190,8 @@ export function Tree<
180190 } as React . CSSProperties
181191 }
182192 tabIndex = { 0 }
183- // When tree viewer is focused, move focus to last focused node
184193 onFocus = { ( event ) : void => {
185- // Don't handle bubbled events
186194 if ( event . currentTarget !== event . target ) return ;
187- // If user wants to edit tree ranks, allow tree ranks to receive focus
188195 if ( isEditingRanks ) return ;
189196 event . preventDefault ( ) ;
190197 } }
0 commit comments