@@ -7,6 +7,7 @@ import { params } from '../utils/query';
7
7
import { fetchData , setBuildsStatus } from '../utils/Utils' ;
8
8
import BuildLink from './BuildLink' ;
9
9
import BuildStatus from './Summary/BuildStatus' ;
10
+ import { useVisibility } from 'reactjs-visibility' ;
10
11
11
12
// Set the page size for the table.
12
13
const pageSize = 5 ;
@@ -18,11 +19,12 @@ function TopLevelBuildTable(props) {
18
19
// Declare two state variables, currentPage and buildInfo, using the useState hook.
19
20
const [ currentPage , setCurrentPage ] = useState ( 1 ) ;
20
21
const [ buildInfo , setBuildInfo ] = useState ( [ ] ) ;
22
+ const { ref, visible } = useVisibility ( ) ;
21
23
22
24
// Use the useEffect hook to fetch data and update the component state when certain props or state variables change.
23
25
useEffect ( ( ) => {
24
- fetchDataAndUpdate ( ) ;
25
- } , [ buildName , url , currentPage ] ) ;
26
+ if ( visible && ! buildInfo . length ) fetchDataAndUpdate ( ) ;
27
+ } , [ buildName , url , currentPage , visible ] ) ;
26
28
27
29
// Declare a function that updates the totals for each build.
28
30
async function updateTotals ( buildInfo ) {
@@ -415,27 +417,30 @@ function TopLevelBuildTable(props) {
415
417
] ;
416
418
417
419
return (
418
- < Table
419
- columns = { columns }
420
- dataSource = { buildInfo }
421
- title = { ( ) => (
422
- < div >
423
- < Link
424
- to = { {
425
- pathname : '/builds' ,
426
- search : params ( {
427
- buildName,
428
- url,
429
- type,
430
- } ) ,
431
- } }
432
- >
433
- < b > { buildName } </ b > in server { url }
434
- </ Link >
435
- </ div >
436
- ) }
437
- pagination = { { pageSize, onChange } }
438
- />
420
+ < div ref = { ref } >
421
+ < Table
422
+ columns = { columns }
423
+ dataSource = { buildInfo }
424
+ title = { ( ) => (
425
+ < div >
426
+ < Link
427
+ to = { {
428
+ pathname : '/builds' ,
429
+ search : params ( {
430
+ buildName,
431
+ url,
432
+ type,
433
+ } ) ,
434
+ } }
435
+ >
436
+ < b > { buildName } </ b > in server { url }
437
+ </ Link >
438
+ </ div >
439
+ ) }
440
+ pagination = { { pageSize, onChange } }
441
+ />
442
+ { ! buildInfo . length && < div style = { { height : 1000 } } /> }
443
+ </ div >
439
444
) ;
440
445
}
441
446
}
0 commit comments