fix: bee data auto-refresh (#436)

This commit is contained in:
Vojtech Simetka
2022-06-24 14:03:07 +02:00
committed by GitHub
parent 2221d0e7c8
commit 4cd580ca7f
2 changed files with 17 additions and 11 deletions
+9 -2
View File
@@ -6,17 +6,24 @@ import { Waiting } from '../../components/Waiting'
import { Context } from '../../providers/Bee'
import { ROUTES } from '../../routes'
export default function Settings(): ReactElement {
const [startedAt] = useState(Date.now())
const STARTED_UPGRADE_AT = 'started-upgrade-at'
export default function LightModeRestart(): ReactElement {
const [startedAt] = useState(Number.parseInt(localStorage.getItem(STARTED_UPGRADE_AT) ?? Date.now().toFixed()))
const { apiHealth, nodeInfo } = useContext(Context)
const navigate = useNavigate()
useEffect(() => {
localStorage.setItem(STARTED_UPGRADE_AT, startedAt.toFixed())
}, [startedAt])
useEffect(() => {
if (Date.now() - startedAt < 45_000) {
return
}
if (apiHealth && nodeInfo?.beeMode === BeeModes.LIGHT) {
localStorage.removeItem(STARTED_UPGRADE_AT)
navigate(ROUTES.INFO)
}
}, [startedAt, navigate, nodeInfo, apiHealth])