commit
4047a7ec23
378 changed files with 29334 additions and 0 deletions
23
hooks/useVersion.js
Normal file
23
hooks/useVersion.js
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
import { useEffect, useCallback } from 'react';
|
||||
import { useDispatch, useSelector } from 'react-redux';
|
||||
import { checkVersion } from 'redux/actions/app';
|
||||
import { VERSION_CHECK } from 'lib/constants';
|
||||
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() });
|
||||
}, [versions]);
|
||||
|
||||
useEffect(() => {
|
||||
if (check && !versions.latest) {
|
||||
dispatch(checkVersion());
|
||||
}
|
||||
}, [versions, check]);
|
||||
|
||||
return { ...versions, checked, updateCheck };
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue