@@ -323,6 +323,7 @@ function PreviewContent({
323
323
setIgnoreClick = { setIgnoreClick }
324
324
isPlayingBack = { isPlayingBack }
325
325
onTimeUpdate = { onTimeUpdate }
326
+ windowVisible = { true }
326
327
/>
327
328
) ;
328
329
} else if ( isCurrentHour ( review . start_time ) ) {
@@ -334,6 +335,7 @@ function PreviewContent({
334
335
setIgnoreClick = { setIgnoreClick }
335
336
isPlayingBack = { isPlayingBack }
336
337
onTimeUpdate = { onTimeUpdate }
338
+ windowVisible = { true }
337
339
/>
338
340
) ;
339
341
}
@@ -349,6 +351,7 @@ type VideoPreviewProps = {
349
351
setIgnoreClick : ( ignore : boolean ) => void ;
350
352
isPlayingBack : ( ended : boolean ) => void ;
351
353
onTimeUpdate ?: ( time : number | undefined ) => void ;
354
+ windowVisible : boolean ;
352
355
} ;
353
356
export function VideoPreview ( {
354
357
relevantPreview,
@@ -360,6 +363,7 @@ export function VideoPreview({
360
363
setIgnoreClick,
361
364
isPlayingBack,
362
365
onTimeUpdate,
366
+ windowVisible,
363
367
} : VideoPreviewProps ) {
364
368
const playerRef = useRef < HTMLVideoElement | null > ( null ) ;
365
369
const sliderRef = useRef < HTMLDivElement | null > ( null ) ;
@@ -409,6 +413,10 @@ export function VideoPreview({
409
413
// time progress update
410
414
411
415
const onProgress = useCallback ( ( ) => {
416
+ if ( ! windowVisible ) {
417
+ return ;
418
+ }
419
+
412
420
if ( onTimeUpdate ) {
413
421
onTimeUpdate (
414
422
relevantPreview . start + ( playerRef . current ?. currentTime || 0 ) ,
@@ -458,7 +466,7 @@ export function VideoPreview({
458
466
459
467
// we know that these deps are correct
460
468
// eslint-disable-next-line react-hooks/exhaustive-deps
461
- } , [ setProgress , lastPercent ] ) ;
469
+ } , [ setProgress , lastPercent , windowVisible ] ) ;
462
470
463
471
// manual playback
464
472
// safari is incapable of playing at a speed > 2x
@@ -596,6 +604,7 @@ type InProgressPreviewProps = {
596
604
setIgnoreClick : ( ignore : boolean ) => void ;
597
605
isPlayingBack : ( ended : boolean ) => void ;
598
606
onTimeUpdate ?: ( time : number | undefined ) => void ;
607
+ windowVisible : boolean ;
599
608
} ;
600
609
export function InProgressPreview ( {
601
610
review,
@@ -606,6 +615,7 @@ export function InProgressPreview({
606
615
setIgnoreClick,
607
616
isPlayingBack,
608
617
onTimeUpdate,
618
+ windowVisible,
609
619
} : InProgressPreviewProps ) {
610
620
const apiHost = useApiHost ( ) ;
611
621
const sliderRef = useRef < HTMLDivElement | null > ( null ) ;
@@ -620,7 +630,7 @@ export function InProgressPreview({
620
630
const [ key , setKey ] = useState ( 0 ) ;
621
631
622
632
const handleLoad = useCallback ( ( ) => {
623
- if ( ! previewFrames ) {
633
+ if ( ! previewFrames || ! windowVisible ) {
624
634
return ;
625
635
}
626
636
0 commit comments