Merged in feature/IO-2733-pwa-timer (pull request #1717)

IO-2733 Add Timer Started check to prevent auto refresh early.
This commit is contained in:
Patrick Fic
2024-09-13 16:59:58 +00:00

View File

@@ -1,7 +1,7 @@
import { AlertOutlined } from "@ant-design/icons"; import { AlertOutlined } from "@ant-design/icons";
import { Alert, Button, Col, notification, Row, Space } from "antd"; import { Alert, Button, Col, notification, Row, Space } from "antd";
import i18n from "i18next"; import i18n from "i18next";
import React, { useCallback, useEffect } from "react"; import React, { useCallback, useEffect, useState } from "react";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import { connect } from "react-redux"; import { connect } from "react-redux";
import { createStructuredSelector } from "reselect"; import { createStructuredSelector } from "reselect";
@@ -20,6 +20,7 @@ const mapDispatchToProps = (dispatch) => ({
export function UpdateAlert({ updateAvailable }) { export function UpdateAlert({ updateAvailable }) {
const { t } = useTranslation(); const { t } = useTranslation();
const [timerStarted, setTimerStarted] = useState(false);
const [ const [
timeLeft, timeLeft,
{ {
@@ -58,6 +59,7 @@ export function UpdateAlert({ updateAvailable }) {
useEffect(() => { useEffect(() => {
if (needRefresh) { if (needRefresh) {
start(); start();
setTimerStarted(true);
} }
}, [start, needRefresh, offlineReady]); }, [start, needRefresh, offlineReady]);
@@ -79,10 +81,10 @@ export function UpdateAlert({ updateAvailable }) {
placement: "bottomRight" placement: "bottomRight"
}); });
} }
if (needRefresh && timeLeft <= 0) { if (needRefresh && timerStarted && timeLeft <= 0) {
ReloadNewVersion(); ReloadNewVersion();
} }
}, [timeLeft, t, needRefresh, ReloadNewVersion]); }, [timeLeft, t, needRefresh, ReloadNewVersion, timerStarted]);
if (!needRefresh) return null; if (!needRefresh) return null;