import { useState } from 'react'; import { toast } from 'react-toastify'; import DownloadIcon from '@mui/icons-material/GetApp'; import { Box, Button, Grid2 as Grid, Typography } from '@mui/material'; import * as SystemApi from 'api/system'; import { API, callAction } from 'api/app'; import { useRequest } from 'alova/client'; import type { APIcall } from 'app/main/types'; import RestartMonitor from 'app/status/RestartMonitor'; import { FormLoader, SectionContent, SingleUpload, useLayoutTitle } from 'components'; import { useI18nContext } from 'i18n/i18n-react'; import { saveFile } from 'utils'; const DownloadUpload = () => { const { LL } = useI18nContext(); const [restarting, setRestarting] = useState(false); const { send: sendExportData } = useRequest( (type: string) => callAction({ action: 'export', param: type }), { immediate: false } ) .onSuccess((event) => { saveFile(event.data, event.args[0], '.json'); toast.info(LL.DOWNLOAD_SUCCESSFUL()); }) .onError((error) => { toast.error(error.message); }); const { send: sendAPI } = useRequest((data: APIcall) => API(data), { immediate: false }); const { data, send: loadData, error } = useRequest(SystemApi.readSystemStatus); const doRestart = async () => { setRestarting(true); await sendAPI({ device: 'system', cmd: 'restart', id: 0 }).catch( (error: Error) => { toast.error(error.message); } ); }; useLayoutTitle(LL.DOWNLOAD_UPLOAD()); const content = () => { if (!data) { return ; } return ( <> {LL.DOWNLOAD(0)} {LL.DOWNLOAD_SETTINGS_TEXT()}. {LL.UPLOAD()} {LL.UPLOAD_TEXT()}. ); }; return ( {restarting ? : content()} ); }; export default DownloadUpload;