Moving restart/shutdown buttons back to Settings page.

This commit is contained in:
Roland 2023-08-19 20:38:34 -06:00
parent 3d6ad99f5b
commit cc84f20072
No known key found for this signature in database
GPG key ID: 9D6DBD3ACF11AB93
2 changed files with 112 additions and 112 deletions

View file

@ -1,10 +1,114 @@
import React from "react";
import {getSettings, saveSettings} from "../../api";
import {getSettings, postRestart, postShutdown, saveSettings} from "../../api";
import {Button, Form, FormGroup, FormInput, Header, Loader, Modal, ModalContent, ModalHeader, Segment} from "../Theme";
import {Container, Dimmer, Icon} from "semantic-ui-react";
import {ThemeContext} from "../../contexts/contexts";
import {APIButton, HelpPopup, HotspotToggle, ThrottleToggle, Toggle, WROLModeMessage} from "../Common";
import QRCode from "react-qr-code";
import {useDockerized} from "../../hooks/customHooks";
import {toast} from "react-semantic-toasts-2";
export function ShutdownButton() {
const dockerized = useDockerized();
const handleShutdown = async () => {
try {
const response = await postShutdown();
if (response && response['code'] === 'SHUTDOWN_FAILED') {
toast({
title: 'Shutdown Failed',
description: response['error'],
time: 5000,
type: "error",
})
} else if (response && response['code'] === 'NATIVE_ONLY') {
toast({
title: 'Shutdown Failed',
description: 'Cannot shutdown while running in Docker',
time: 5000,
type: "error",
})
} else if (response !== null) {
toast({
title: 'Shutdown Failed',
description: 'Unknown error when attempting shutdown',
time: 5000,
type: "error",
})
}
} catch (e) {
toast({
title: 'Shutdown Failed',
description: 'Failed to request WROLPi shutdown',
time: 5000,
type: "error",
})
throw e;
}
}
return <APIButton
size='huge'
color='red'
onClick={handleShutdown}
confirmContent='Are you sure you want to turn off your WROLPi?'
confirmButton='Shutdown'
disabled={dockerized}
>
Shutdown
</APIButton>
}
export function RestartButton() {
const dockerized = useDockerized();
const handleRestart = async () => {
try {
const response = await postRestart();
if (response && response['code'] === 'SHUTDOWN_FAILED') {
toast({
title: 'Restart Failed',
description: response['error'],
time: 5000,
type: "error",
})
} else if (response && response['code'] === 'NATIVE_ONLY') {
toast({
title: 'Restart Failed',
description: 'Cannot restart while running in Docker',
time: 5000,
type: "error",
})
} else if (response !== null) {
toast({
title: 'Restart Failed',
description: 'Unknown error when attempting restart',
time: 5000,
type: "error",
})
}
} catch (e) {
toast({
title: 'Restart Failed',
description: 'Failed to request WROLPi restart',
time: 5000,
type: "error",
})
throw e;
}
}
return <APIButton
size='huge'
color='yellow'
onClick={handleRestart}
confirmContent='Are you sure you want to restart your WROLPi?'
confirmButton='Restart'
disabled={dockerized}
>
Restart
</APIButton>
}
export class SettingsPage extends React.Component {
@ -231,6 +335,12 @@ export class SettingsPage extends React.Component {
</Form>
</Segment>
<Segment>
<Header as='h3'>Control WROLPi</Header>
<RestartButton/>
<ShutdownButton/>
</Segment>
</Container>}
</ThemeContext.Consumer>
}

View file

@ -1,12 +1,9 @@
import {Header, Progress, Segment, Statistic, StatisticGroup} from "../Theme";
import React, {useContext} from "react";
import {APIButton, humanBandwidth, humanFileSize, LoadStatistic, useTitle} from "../Common";
import {humanBandwidth, humanFileSize, LoadStatistic, useTitle} from "../Common";
import {ProgressPlaceholder} from "../Placeholder";
import Grid from "semantic-ui-react/dist/commonjs/collections/Grid";
import {Media, StatusContext} from "../../contexts/contexts";
import {useDockerized} from "../../hooks/customHooks";
import {postRestart, postShutdown} from "../../api";
import {toast} from "react-semantic-toasts-2";
function DriveInfo({used, size, percent, mount}) {
let color;
@ -145,108 +142,6 @@ export function CPUUsageProgress({value, label}) {
return <Progress percent={value} progress color={color} label={label}/>
}
export function ShutdownButton() {
const dockerized = useDockerized();
const handleShutdown = async () => {
try {
const response = await postShutdown();
if (response && response['code'] === 'SHUTDOWN_FAILED') {
toast({
title: 'Shutdown Failed',
description: response['error'],
time: 5000,
type: "error",
})
} else if (response && response['code'] === 'NATIVE_ONLY') {
toast({
title: 'Shutdown Failed',
description: 'Cannot shutdown while running in Docker',
time: 5000,
type: "error",
})
} else if (response !== null) {
toast({
title: 'Shutdown Failed',
description: 'Unknown error when attempting shutdown',
time: 5000,
type: "error",
})
}
} catch (e) {
toast({
title: 'Shutdown Failed',
description: 'Failed to request WROLPi shutdown',
time: 5000,
type: "error",
})
throw e;
}
}
return <APIButton
size='huge'
color='red'
onClick={handleShutdown}
confirmContent='Are you sure you want to turn off your WROLPi?'
confirmButton='Shutdown'
disabled={dockerized}
>
Shutdown
</APIButton>
}
export function RestartButton() {
const dockerized = useDockerized();
const handleRestart = async () => {
try {
const response = await postRestart();
if (response && response['code'] === 'SHUTDOWN_FAILED') {
toast({
title: 'Restart Failed',
description: response['error'],
time: 5000,
type: "error",
})
} else if (response && response['code'] === 'NATIVE_ONLY') {
toast({
title: 'Restart Failed',
description: 'Cannot restart while running in Docker',
time: 5000,
type: "error",
})
} else if (response !== null) {
toast({
title: 'Restart Failed',
description: 'Unknown error when attempting restart',
time: 5000,
type: "error",
})
}
} catch (e) {
toast({
title: 'Restart Failed',
description: 'Failed to request WROLPi restart',
time: 5000,
type: "error",
})
throw e;
}
}
return <APIButton
size='huge'
color='yellow'
onClick={handleRestart}
confirmContent='Are you sure you want to restart your WROLPi?'
confirmButton='Restart'
disabled={dockerized}
>
Restart
</APIButton>
}
export function Status() {
useTitle('Status');
@ -345,11 +240,6 @@ export function Status() {
<Header as='h2'>Drive Bandwidth</Header>
{disk_bandwidth.map((disk) => <DiskBandwidth key={disk['name']} {...disk}/>)}
</Segment>
<Segment>
<RestartButton/>
<ShutdownButton/>
</Segment>
</Media>
</>
}