Fix version check.

This commit is contained in:
Mike Cao 2020-10-02 10:34:22 -07:00
parent b35c5b57da
commit 48a1994219
2 changed files with 8 additions and 7 deletions

View File

@ -7,21 +7,21 @@ import Button from './Button';
import useForceUpdate from '../../hooks/useForceUpdate';
export default function UpdateNotice() {
const forceUpdte = useForceUpdate();
const { hasUpdate, latest, updateCheck } = useVersion(true);
const forceUpdate = useForceUpdate();
const { hasUpdate, checked, latest, updateCheck } = useVersion(true);
function handleViewClick() {
location.href = 'https://github.com/mikecao/umami/releases';
updateCheck();
forceUpdte();
forceUpdate();
}
function handleDismissClick() {
updateCheck();
forceUpdte();
forceUpdate();
}
if (!hasUpdate) {
if (!hasUpdate || checked) {
return null;
}

View File

@ -2,11 +2,12 @@ import { useEffect, useCallback } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { checkVersion } from 'redux/actions/app';
import { VERSION_CHECK } from 'lib/constants';
import { setItem } from 'lib/web';
import { getItem, setItem } from 'lib/web';
export default function useVersion(check) {
const dispatch = useDispatch();
const versions = useSelector(state => state.app.versions);
const checked = versions.latest === getItem(VERSION_CHECK)?.version;
const updateCheck = useCallback(() => {
setItem(VERSION_CHECK, { version: versions.latest, time: Date.now() });
@ -18,5 +19,5 @@ export default function useVersion(check) {
}
}, [versions, check]);
return { ...versions, updateCheck };
return { ...versions, checked, updateCheck };
}