mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-11-20 15:06:19 -05:00
Changing download enable/disable button into a toggle switch.
This commit is contained in:
parent
2ed3ef9d00
commit
d935da95f2
4 changed files with 87 additions and 86 deletions
|
|
@ -11,35 +11,19 @@ import {
|
|||
Placeholder,
|
||||
Table
|
||||
} from "semantic-ui-react";
|
||||
import {
|
||||
getConfig,
|
||||
getDownloaders,
|
||||
getDownloads,
|
||||
killDownload,
|
||||
killDownloads,
|
||||
postDownload,
|
||||
saveConfig,
|
||||
startDownloads
|
||||
} from "../api";
|
||||
import {getConfig, getDownloads, killDownload, postDownload, saveConfig} from "../api";
|
||||
import TimezoneSelect from 'react-timezone-select';
|
||||
import {PageContainer, secondsToDate, secondsToFrequency, TabLinks, textEllipsis, WROLModeMessage} from "./Common";
|
||||
import {
|
||||
DisableDownloadsToggle,
|
||||
HotspotToggle,
|
||||
PageContainer,
|
||||
secondsToDate,
|
||||
secondsToFrequency,
|
||||
TabLinks,
|
||||
textEllipsis,
|
||||
WROLModeMessage
|
||||
} from "./Common";
|
||||
import {Route} from "react-router-dom";
|
||||
import {useHotspot} from "../hooks/customHooks";
|
||||
|
||||
function HotspotToggle() {
|
||||
let {on, setHotspot} = useHotspot();
|
||||
return (
|
||||
<>
|
||||
<Checkbox toggle
|
||||
label='Toggle the WiFi Hotspot. Only supported on Raspberry Pi.'
|
||||
disabled={on === null}
|
||||
defaultIndeterminate={on === null}
|
||||
checked={on === true}
|
||||
onChange={(e, data) => setHotspot(data.checked)}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
class Settings extends React.Component {
|
||||
|
||||
|
|
@ -95,9 +79,7 @@ class Settings extends React.Component {
|
|||
<Container fluid>
|
||||
<WROLModeMessage content='Settings are disabled because WROL Mode is enabled.'/>
|
||||
|
||||
<p>
|
||||
<HotspotToggle/>
|
||||
</p>
|
||||
<HotspotToggle/>
|
||||
|
||||
<Divider/>
|
||||
<p>
|
||||
|
|
@ -327,17 +309,6 @@ class Downloads extends React.Component {
|
|||
|
||||
async componentDidMount() {
|
||||
await this.fetchDownloads();
|
||||
await this.fetchStatus();
|
||||
}
|
||||
|
||||
killDownloads = async () => {
|
||||
await killDownloads();
|
||||
this.setState({stopOpen: false}, this.fetchStatus);
|
||||
}
|
||||
|
||||
startDownloads = async () => {
|
||||
await startDownloads();
|
||||
this.setState({stopOpen: false}, this.fetchStatus);
|
||||
}
|
||||
|
||||
closeStop = () => {
|
||||
|
|
@ -357,11 +328,6 @@ class Downloads extends React.Component {
|
|||
});
|
||||
}
|
||||
|
||||
fetchStatus = async () => {
|
||||
let data = await getDownloaders();
|
||||
this.setState({disabled: data['manager_disabled']});
|
||||
}
|
||||
|
||||
render() {
|
||||
let tablePlaceholder = (
|
||||
<Placeholder>
|
||||
|
|
@ -400,7 +366,9 @@ class Downloads extends React.Component {
|
|||
onceTable = (<Table>
|
||||
{stoppableHeader}
|
||||
<Table.Body>
|
||||
{this.state.once_downloads.map((i) => <StoppableRow {...i} fetchDownloads={this.fetchDownloads}/>)}
|
||||
{this.state.once_downloads.map((i) =>
|
||||
<StoppableRow {...i} fetchDownloads={this.fetchDownloads} key={i.id}/>
|
||||
)}
|
||||
</Table.Body>
|
||||
</Table>);
|
||||
}
|
||||
|
|
@ -412,46 +380,15 @@ class Downloads extends React.Component {
|
|||
recurringTable = (<Table>
|
||||
{nonStoppableHeader}
|
||||
<Table.Body>
|
||||
{this.state.recurring_downloads.map((i) => <DownloadRow {...i}/>)}
|
||||
{this.state.recurring_downloads.map((i) => <DownloadRow {...i} key={i.id}/>)}
|
||||
</Table.Body>
|
||||
</Table>);
|
||||
}
|
||||
|
||||
let {stopOpen} = this.state;
|
||||
let allButton = (<>
|
||||
<Button
|
||||
onClick={this.openStop}
|
||||
color='red'
|
||||
>Disable Downloads</Button>
|
||||
<Confirm
|
||||
open={stopOpen}
|
||||
content='Are you sure you want to stop all downloads?'
|
||||
confirmButton='Stop'
|
||||
onCancel={this.closeStop}
|
||||
onConfirm={this.killDownloads}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
if (this.state.disabled === true) {
|
||||
allButton = (<>
|
||||
<Button
|
||||
onClick={this.openStop}
|
||||
color='green'
|
||||
>Enable Downloads</Button>
|
||||
<Confirm
|
||||
open={stopOpen}
|
||||
content='Are you sure you want to start all downloads?'
|
||||
confirmButton='Start'
|
||||
onCancel={this.closeStop}
|
||||
onConfirm={this.startDownloads}
|
||||
/>
|
||||
</>);
|
||||
}
|
||||
|
||||
return (
|
||||
<div>
|
||||
<WROLModeMessage content='Downloads are disabled because WROL Mode is enabled.'/>
|
||||
{allButton}
|
||||
<DisableDownloadsToggle/>
|
||||
<Header as='h1'>Downloads</Header>
|
||||
{onceTable}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,10 +1,11 @@
|
|||
import React, {useEffect, useState} from "react";
|
||||
import {Card, Container, Form, Icon, Image, Input, Menu, Pagination, Responsive} from 'semantic-ui-react';
|
||||
import {Card, Checkbox, Container, Form, Icon, Image, Input, Menu, Pagination, Responsive} from 'semantic-ui-react';
|
||||
import {Link, NavLink} from "react-router-dom";
|
||||
import Button from "semantic-ui-react/dist/commonjs/elements/Button";
|
||||
import Grid from "semantic-ui-react/dist/commonjs/collections/Grid";
|
||||
import Message from "semantic-ui-react/dist/commonjs/collections/Message";
|
||||
import {getConfig} from "../api";
|
||||
import {useDownloaders, useHotspot} from "../hooks/customHooks";
|
||||
|
||||
export const API_URI = `http://${window.location.host}/api`;
|
||||
export const VIDEOS_API = `${API_URI}/videos`;
|
||||
|
|
@ -643,3 +644,24 @@ export function CardGroupCentered(props) {
|
|||
</>
|
||||
)
|
||||
}
|
||||
|
||||
export function HotspotToggle() {
|
||||
let {on, setHotspot} = useHotspot();
|
||||
return <Checkbox toggle
|
||||
label={on === null ?
|
||||
'Toggle the WiFi Hotspot. Only supported on Raspberry Pi.' : 'Toggle WiFi Hotspot'}
|
||||
disabled={on === null}
|
||||
checked={on === true}
|
||||
onChange={(e, data) => setHotspot(data.checked)}
|
||||
/>;
|
||||
}
|
||||
|
||||
export function DisableDownloadsToggle() {
|
||||
let {on, setDownloads} = useDownloaders();
|
||||
return <Checkbox toggle
|
||||
label={on ? 'Downloading Enabled' : 'Downloading Disabled'}
|
||||
disabled={on === null}
|
||||
checked={on === true}
|
||||
onChange={(e, data) => setDownloads(data.checked)}
|
||||
/>;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue