mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-07 16:29:51 +03:00
82 lines
2.1 KiB
TypeScript
82 lines
2.1 KiB
TypeScript
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<string>();
|
|
|
|
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 (
|
|
<Dialog fullWidth={true} sx={dialogStyle} open={true}>
|
|
<DialogContent dividers>
|
|
<Box m={0} py={0} display="flex" alignItems="center" flexDirection="column">
|
|
<Typography
|
|
color="secondary"
|
|
variant="h6"
|
|
fontWeight={400}
|
|
textAlign="center"
|
|
>
|
|
{data?.status === 'uploading'
|
|
? LL.WAIT_FIRMWARE()
|
|
: data?.status === 'restarting'
|
|
? LL.APPLICATION_RESTARTING()
|
|
: data?.status === 'ready'
|
|
? LL.RESTARTING_PRE()
|
|
: LL.RESTARTING_POST()}
|
|
…
|
|
</Typography>
|
|
<Typography mt={2} variant="h6" fontWeight={400} textAlign="center">
|
|
{LL.PLEASE_WAIT()}
|
|
</Typography>
|
|
|
|
{errorMessage ? (
|
|
<MessageBox my={2} level="error" message={errorMessage} />
|
|
) : (
|
|
<Box py={2}>
|
|
<CircularProgress size={32} />
|
|
</Box>
|
|
)}
|
|
</Box>
|
|
</DialogContent>
|
|
</Dialog>
|
|
);
|
|
};
|
|
|
|
export default RestartMonitor;
|