auto refresh in foreground only (#11750)

This commit is contained in:
Vadim Ogievetsky 2021-10-05 18:48:23 -07:00 committed by GitHub
parent 2593df5e5b
commit c1e0e6825f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 1 deletions

View File

@ -47,6 +47,7 @@ export const RefreshButton = React.memo(function RefreshButton(props: RefreshBut
icon={IconNames.REFRESH}
text="Refresh"
onRefresh={onRefresh}
foregroundOnly
localStorageKey={localStorageKey}
/>
);

View File

@ -22,7 +22,7 @@ import { Popover2 } from '@blueprintjs/popover2';
import React, { useState } from 'react';
import { useInterval } from '../../hooks';
import { localStorageGet, LocalStorageKeys, localStorageSet } from '../../utils';
import { isInBackground, localStorageGet, LocalStorageKeys, localStorageSet } from '../../utils';
export interface DelayLabel {
label: string;
@ -35,6 +35,7 @@ export interface TimedButtonProps extends ButtonProps {
localStorageKey?: LocalStorageKeys;
label: string;
defaultDelay: number;
foregroundOnly?: boolean;
}
export const TimedButton = React.memo(function TimedButton(props: TimedButtonProps) {
@ -46,6 +47,7 @@ export const TimedButton = React.memo(function TimedButton(props: TimedButtonPro
text,
icon,
defaultDelay,
foregroundOnly,
localStorageKey,
...other
} = props;
@ -57,6 +59,7 @@ export const TimedButton = React.memo(function TimedButton(props: TimedButtonPro
);
useInterval(() => {
if (foregroundOnly && isInBackground()) return;
onRefresh(true);
}, selectedDelay);

View File

@ -404,3 +404,7 @@ export function stringifyValue(value: unknown): string {
return String(value);
}
}
export function isInBackground(): boolean {
return document.visibilityState === 'hidden';
}