mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-07 16:29:51 +03:00
remove Restart
This commit is contained in:
@@ -5,12 +5,9 @@ import { toast } from 'react-toastify';
|
|||||||
|
|
||||||
import CancelIcon from '@mui/icons-material/Cancel';
|
import CancelIcon from '@mui/icons-material/Cancel';
|
||||||
import CircleIcon from '@mui/icons-material/Circle';
|
import CircleIcon from '@mui/icons-material/Circle';
|
||||||
import PowerSettingsNewIcon from '@mui/icons-material/PowerSettingsNew';
|
|
||||||
import WarningIcon from '@mui/icons-material/Warning';
|
import WarningIcon from '@mui/icons-material/Warning';
|
||||||
import { Box, Button, Typography } from '@mui/material';
|
import { Box, Button, Typography } from '@mui/material';
|
||||||
|
|
||||||
import * as SystemApi from 'api/system';
|
|
||||||
|
|
||||||
import {
|
import {
|
||||||
Body,
|
Body,
|
||||||
Cell,
|
Cell,
|
||||||
@@ -26,11 +23,9 @@ import {
|
|||||||
BlockNavigation,
|
BlockNavigation,
|
||||||
ButtonRow,
|
ButtonRow,
|
||||||
FormLoader,
|
FormLoader,
|
||||||
MessageBox,
|
|
||||||
SectionContent,
|
SectionContent,
|
||||||
useLayoutTitle
|
useLayoutTitle
|
||||||
} from 'components';
|
} from 'components';
|
||||||
import RestartMonitor from 'framework/system/RestartMonitor';
|
|
||||||
import { useI18nContext } from 'i18n/i18n-react';
|
import { useI18nContext } from 'i18n/i18n-react';
|
||||||
|
|
||||||
import * as EMSESP from './api';
|
import * as EMSESP from './api';
|
||||||
@@ -40,13 +35,10 @@ import type { ModuleItem, Modules } from './types';
|
|||||||
const Modules: FC = () => {
|
const Modules: FC = () => {
|
||||||
const { LL } = useI18nContext();
|
const { LL } = useI18nContext();
|
||||||
const [numChanges, setNumChanges] = useState<number>(0);
|
const [numChanges, setNumChanges] = useState<number>(0);
|
||||||
const [licenseChanges, setLicenseChanges] = useState<number>(0);
|
|
||||||
const blocker = useBlocker(numChanges !== 0);
|
const blocker = useBlocker(numChanges !== 0);
|
||||||
|
|
||||||
const [selectedModuleItem, setSelectedModuleItem] = useState<ModuleItem>();
|
const [selectedModuleItem, setSelectedModuleItem] = useState<ModuleItem>();
|
||||||
const [dialogOpen, setDialogOpen] = useState<boolean>(false);
|
const [dialogOpen, setDialogOpen] = useState<boolean>(false);
|
||||||
const [restarting, setRestarting] = useState<boolean>(false);
|
|
||||||
const [restartNeeded, setRestartNeeded] = useState<boolean>(false);
|
|
||||||
|
|
||||||
const {
|
const {
|
||||||
data: modules,
|
data: modules,
|
||||||
@@ -56,17 +48,6 @@ const Modules: FC = () => {
|
|||||||
initialData: []
|
initialData: []
|
||||||
});
|
});
|
||||||
|
|
||||||
const { send: restartCommand } = useRequest(SystemApi.restart(), {
|
|
||||||
immediate: false
|
|
||||||
});
|
|
||||||
|
|
||||||
const restart = async () => {
|
|
||||||
await restartCommand().catch((error: Error) => {
|
|
||||||
toast.error(error.message);
|
|
||||||
});
|
|
||||||
setRestarting(true);
|
|
||||||
};
|
|
||||||
|
|
||||||
const { send: writeModules } = useRequest(
|
const { send: writeModules } = useRequest(
|
||||||
(data: Modules) => EMSESP.writeModules(data),
|
(data: Modules) => EMSESP.writeModules(data),
|
||||||
{
|
{
|
||||||
@@ -140,17 +121,12 @@ const Modules: FC = () => {
|
|||||||
return mi.enabled !== mi.o_enabled || mi.license !== mi.o_license;
|
return mi.enabled !== mi.o_enabled || mi.license !== mi.o_license;
|
||||||
}
|
}
|
||||||
|
|
||||||
function hasModuleLicenseChanged(mi: ModuleItem) {
|
|
||||||
return mi.license !== mi.o_license;
|
|
||||||
}
|
|
||||||
|
|
||||||
const updateModuleItem = (updatedItem: ModuleItem) => {
|
const updateModuleItem = (updatedItem: ModuleItem) => {
|
||||||
updateState('modules', (data: ModuleItem[]) => {
|
updateState('modules', (data: ModuleItem[]) => {
|
||||||
const new_data = data.map((mi) =>
|
const new_data = data.map((mi) =>
|
||||||
mi.id === updatedItem.id ? { ...mi, ...updatedItem } : mi
|
mi.id === updatedItem.id ? { ...mi, ...updatedItem } : mi
|
||||||
);
|
);
|
||||||
setNumChanges(new_data.filter((mi) => hasModulesChanged(mi)).length);
|
setNumChanges(new_data.filter((mi) => hasModulesChanged(mi)).length);
|
||||||
setLicenseChanges(new_data.filter((mi) => hasModuleLicenseChanged(mi)).length);
|
|
||||||
return new_data;
|
return new_data;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@@ -172,7 +148,6 @@ const Modules: FC = () => {
|
|||||||
.finally(() => {
|
.finally(() => {
|
||||||
setNumChanges(0);
|
setNumChanges(0);
|
||||||
});
|
});
|
||||||
setRestartNeeded(licenseChanges > 0);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const renderContent = () => {
|
const renderContent = () => {
|
||||||
@@ -213,8 +188,10 @@ const Modules: FC = () => {
|
|||||||
<HeaderRow>
|
<HeaderRow>
|
||||||
<HeaderCell />
|
<HeaderCell />
|
||||||
<HeaderCell>{LL.NAME(0)}</HeaderCell>
|
<HeaderCell>{LL.NAME(0)}</HeaderCell>
|
||||||
|
{/* TODO translate */}
|
||||||
<HeaderCell>Author</HeaderCell>
|
<HeaderCell>Author</HeaderCell>
|
||||||
<HeaderCell>{LL.VERSION()}</HeaderCell>
|
<HeaderCell>{LL.VERSION()}</HeaderCell>
|
||||||
|
{/* TODO translate */}
|
||||||
<HeaderCell>Message</HeaderCell>
|
<HeaderCell>Message</HeaderCell>
|
||||||
<HeaderCell>{LL.STATUS_OF('')}</HeaderCell>
|
<HeaderCell>{LL.STATUS_OF('')}</HeaderCell>
|
||||||
</HeaderRow>
|
</HeaderRow>
|
||||||
@@ -247,43 +224,30 @@ const Modules: FC = () => {
|
|||||||
)}
|
)}
|
||||||
</Table>
|
</Table>
|
||||||
|
|
||||||
{restartNeeded ? (
|
<Box mt={1} display="flex" flexWrap="wrap">
|
||||||
<MessageBox my={2} level="warning" message={LL.RESTART_TEXT(0)}>
|
<Box flexGrow={1}>
|
||||||
<Button
|
{numChanges !== 0 && (
|
||||||
startIcon={<PowerSettingsNewIcon />}
|
<ButtonRow>
|
||||||
variant="contained"
|
<Button
|
||||||
color="error"
|
startIcon={<CancelIcon />}
|
||||||
onClick={restart}
|
variant="outlined"
|
||||||
>
|
onClick={onCancel}
|
||||||
{LL.RESTART()}
|
color="secondary"
|
||||||
</Button>
|
>
|
||||||
</MessageBox>
|
{LL.CANCEL()}
|
||||||
) : (
|
</Button>
|
||||||
<Box mt={1} display="flex" flexWrap="wrap">
|
<Button
|
||||||
<Box flexGrow={1}>
|
startIcon={<WarningIcon color="warning" />}
|
||||||
{numChanges !== 0 && (
|
variant="contained"
|
||||||
<ButtonRow>
|
color="info"
|
||||||
<Button
|
onClick={saveModules}
|
||||||
startIcon={<CancelIcon />}
|
>
|
||||||
variant="outlined"
|
{LL.APPLY_CHANGES(numChanges)}
|
||||||
onClick={onCancel}
|
</Button>
|
||||||
color="secondary"
|
</ButtonRow>
|
||||||
>
|
)}
|
||||||
{LL.CANCEL()}
|
|
||||||
</Button>
|
|
||||||
<Button
|
|
||||||
startIcon={<WarningIcon color="warning" />}
|
|
||||||
variant="contained"
|
|
||||||
color="info"
|
|
||||||
onClick={saveModules}
|
|
||||||
>
|
|
||||||
{LL.APPLY_CHANGES(numChanges)}
|
|
||||||
</Button>
|
|
||||||
</ButtonRow>
|
|
||||||
)}
|
|
||||||
</Box>
|
|
||||||
</Box>
|
</Box>
|
||||||
)}
|
</Box>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
@@ -291,7 +255,7 @@ const Modules: FC = () => {
|
|||||||
return (
|
return (
|
||||||
<SectionContent>
|
<SectionContent>
|
||||||
{blocker ? <BlockNavigation blocker={blocker} /> : null}
|
{blocker ? <BlockNavigation blocker={blocker} /> : null}
|
||||||
{restarting ? <RestartMonitor /> : renderContent()}
|
{renderContent()}
|
||||||
{selectedModuleItem && (
|
{selectedModuleItem && (
|
||||||
<ModulesDialog
|
<ModulesDialog
|
||||||
open={dialogOpen}
|
open={dialogOpen}
|
||||||
|
|||||||
Reference in New Issue
Block a user