import { useState } from 'react'; import { Box, CircularProgress, Dialog, DialogContent, Typography } from '@mui/material'; import { readSystemStatus } from 'api/system'; import { dialogStyle } from 'CustomTheme'; import { useAutoRequest } from 'alova/client'; import MessageBox from 'components/MessageBox'; import { useI18nContext } from 'i18n/i18n-react'; const RestartMonitor = () => { const [errorMessage, setErrorMessage] = useState(); const { LL } = useI18nContext(); let count = 0; const { data } = useAutoRequest(readSystemStatus, { pollingTime: 1000, force: true, initialData: { status: 'Getting ready...' }, async middleware(_, next) { if (count++ >= 1) { // skip first request (1 second) to allow AsyncWS to send its response await next(); } } }) .onSuccess((event) => { if (event.data.status === 'ready' || event.data.status === undefined) { document.location.href = '/'; } }) .onError((error) => { setErrorMessage(error.message); }); return ( {data?.status === 'uploading' ? LL.WAIT_FIRMWARE() : data?.status === 'restarting' ? LL.APPLICATION_RESTARTING() : data?.status === 'ready' ? LL.RESTARTING_PRE() : LL.RESTARTING_POST()} … {LL.PLEASE_WAIT()} {errorMessage ? ( ) : ( )} ); }; export default RestartMonitor;