Updated check updates logic.

This commit is contained in:
Mike Cao 2022-08-09 14:58:27 -07:00
parent d556806c64
commit 5873a56fff
2 changed files with 9 additions and 10 deletions

View file

@ -6,15 +6,10 @@ import { setItem } from 'lib/web';
import { REPO_URL, VERSION_CHECK } from 'lib/constants';
import Button from './Button';
import styles from './UpdateNotice.module.css';
import useUser from 'hooks/useUser';
import useConfig from 'hooks/useConfig';
export default function UpdateNotice() {
const { user } = useUser();
const { updatesDisabled } = useConfig();
const { latest, checked, hasUpdate, releaseUrl } = useStore();
const [dismissed, setDismissed] = useState(false);
const allowCheck = user?.is_admin && !updatesDisabled;
const updateCheck = useCallback(() => {
setItem(VERSION_CHECK, { version: latest, time: Date.now() });
@ -32,12 +27,12 @@ export default function UpdateNotice() {
}
useEffect(() => {
if (!checked && allowCheck) {
if (!checked) {
checkVersion();
}
}, [checked]);
if (!hasUpdate || dismissed || !allowCheck) {
if (!hasUpdate || dismissed) {
return null;
}