move restarting to parent component - #1920

This commit is contained in:
proddy
2024-08-16 13:48:28 +02:00
parent d3a7ab8fc1
commit 5404537da8
3 changed files with 53 additions and 52 deletions

View File

@@ -1,5 +1,4 @@
// Code inspired by https://medium.com/@dprincecoder/creating-a-drag-and-drop-file-upload-component-in-react-a-step-by-step-guide-4d93b6cc21e0
// (c) Prince Azubuike
// Code inspired by Prince Azubuike from https://medium.com/@dprincecoder/creating-a-drag-and-drop-file-upload-component-in-react-a-step-by-step-guide-4d93b6cc21e0
import { type ChangeEvent, useRef, useState } from 'react';
import CancelIcon from '@mui/icons-material/Cancel';

View File

@@ -2,23 +2,17 @@ import { useEffect, useState } from 'react';
import { toast } from 'react-toastify';
import CancelIcon from '@mui/icons-material/Cancel';
import PowerSettingsNewIcon from '@mui/icons-material/PowerSettingsNew';
import { Box, Button, LinearProgress, Typography } from '@mui/material';
import * as SystemApi from 'api/system';
import { useRequest } from 'alova/client';
import RestartMonitor from 'app/status/RestartMonitor';
import MessageBox from 'components/MessageBox';
import { useI18nContext } from 'i18n/i18n-react';
import DragNdrop from './DragNdrop';
const SingleUpload = () => {
const SingleUpload = ({ setRestartNeeded }) => {
const [md5, setMd5] = useState<string>();
const [restarting, setRestarting] = useState<boolean>(false);
const [restartNeeded, setRestartNeeded] = useState<boolean>(false);
const [file, setFile] = useState<File>();
const { LL } = useI18nContext();
@@ -39,17 +33,6 @@ const SingleUpload = () => {
}
});
const { send: restartCommand } = useRequest(SystemApi.restart(), {
immediate: false
});
const restart = async () => {
await restartCommand().catch((error: Error) => {
toast.error(error.message);
});
setRestarting(true);
};
useEffect(async () => {
if (file) {
console.log('going to upload file ', file.name);
@@ -75,7 +58,7 @@ const SingleUpload = () => {
<Typography variant="body2">{LL.UPLOAD_TEXT()}</Typography>
</Box>
{isUploading || restartNeeded ? (
{isUploading ? (
<>
<Box width="100%" p={2}>
<LinearProgress
@@ -90,17 +73,15 @@ const SingleUpload = () => {
/>
</Box>
{!restartNeeded && (
<Button
sx={{ ml: 2 }}
startIcon={<CancelIcon />}
variant="outlined"
color="error"
onClick={cancelUpload}
>
{LL.CANCEL()}
</Button>
)}
<Button
sx={{ ml: 2 }}
startIcon={<CancelIcon />}
variant="outlined"
color="error"
onClick={cancelUpload}
>
{LL.CANCEL()}
</Button>
</>
) : (
<DragNdrop onFileSelected={setFile} />
@@ -111,21 +92,6 @@ const SingleUpload = () => {
<Typography variant="body2">{'MD5: ' + md5}</Typography>
</Box>
)}
{restartNeeded && (
<MessageBox mt={2} level="warning" message={LL.RESTART_TEXT(0)}>
<Button
startIcon={<PowerSettingsNewIcon />}
variant="contained"
color="error"
onClick={restart}
>
{LL.RESTART()}
</Button>
</MessageBox>
)}
{restarting && <RestartMonitor />}
</>
);
};