From cc84f20072aa2b8add3e1516dd10c7c179978f51 Mon Sep 17 00:00:00 2001 From: Roland Date: Sat, 19 Aug 2023 20:38:34 -0600 Subject: [PATCH] Moving restart/shutdown buttons back to Settings page. --- app/src/components/admin/Settings.js | 112 ++++++++++++++++++++++++++- app/src/components/admin/Status.js | 112 +-------------------------- 2 files changed, 112 insertions(+), 112 deletions(-) diff --git a/app/src/components/admin/Settings.js b/app/src/components/admin/Settings.js index 767172bf..92eb65ab 100644 --- a/app/src/components/admin/Settings.js +++ b/app/src/components/admin/Settings.js @@ -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 + Shutdown + +} + +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 + Restart + +} export class SettingsPage extends React.Component { @@ -231,6 +335,12 @@ export class SettingsPage extends React.Component { + + +
Control WROLPi
+ + +
} } diff --git a/app/src/components/admin/Status.js b/app/src/components/admin/Status.js index b7d43977..f4470714 100644 --- a/app/src/components/admin/Status.js +++ b/app/src/components/admin/Status.js @@ -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 } -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 - Shutdown - -} - -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 - Restart - -} - export function Status() { useTitle('Status'); @@ -345,11 +240,6 @@ export function Status() {
Drive Bandwidth
{disk_bandwidth.map((disk) => )} - - - - - }