mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-12-04 21:59:58 -05:00
Reworking default/empty/error states for all pages. Null is pending, undefined is error.
This commit is contained in:
parent
ee95204d3b
commit
619a88c429
15 changed files with 294 additions and 260 deletions
|
|
@ -4,6 +4,7 @@ import {Link} from "react-router-dom";
|
|||
import {
|
||||
APIButton,
|
||||
DisableDownloadsToggle,
|
||||
ErrorMessage,
|
||||
isoDatetimeToElapsedPopup,
|
||||
secondsToFrequency,
|
||||
textEllipsis,
|
||||
|
|
@ -23,7 +24,6 @@ import {
|
|||
} from "semantic-ui-react";
|
||||
import {Button, Header, Modal, ModalActions, ModalContent, ModalHeader, Placeholder, Segment, Table} from "../Theme";
|
||||
import {useDownloads} from "../../hooks/customHooks";
|
||||
import _ from "lodash";
|
||||
|
||||
function ClearCompleteDownloads({callback}) {
|
||||
async function localClearDownloads() {
|
||||
|
|
@ -245,9 +245,7 @@ class StoppableRow extends React.Component {
|
|||
}
|
||||
|
||||
export function OnceDownloadsTable({downloads, fetchDownloads}) {
|
||||
if (downloads && _.isEmpty(downloads)) {
|
||||
return <Segment>No downloads are scheduled.</Segment>;
|
||||
} else if (downloads) {
|
||||
if (downloads && downloads.length >= 1) {
|
||||
return <>
|
||||
<Table>
|
||||
<TableHeader>
|
||||
|
|
@ -269,19 +267,20 @@ export function OnceDownloadsTable({downloads, fetchDownloads}) {
|
|||
</TableRow>
|
||||
</TableFooter>
|
||||
</Table>
|
||||
</>;
|
||||
} else {
|
||||
return <Placeholder>
|
||||
<PlaceholderLine/>
|
||||
<PlaceholderLine/>
|
||||
</Placeholder>;
|
||||
</>
|
||||
} else if (downloads) {
|
||||
return <Segment>No downloads are scheduled.</Segment>
|
||||
} else if (downloads === undefined) {
|
||||
return <ErrorMessage>Unable to fetch downloads</ErrorMessage>
|
||||
}
|
||||
return <Placeholder>
|
||||
<PlaceholderLine/>
|
||||
<PlaceholderLine/>
|
||||
</Placeholder>
|
||||
}
|
||||
|
||||
export function RecurringDownloadsTable({downloads, fetchDownloads}) {
|
||||
if (downloads && _.isEmpty(downloads)) {
|
||||
return <Segment>No downloads are scheduled.</Segment>;
|
||||
} else if (downloads) {
|
||||
if (downloads && downloads.length >= 1) {
|
||||
return <Table>
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
|
|
@ -295,13 +294,16 @@ export function RecurringDownloadsTable({downloads, fetchDownloads}) {
|
|||
<TableBody>
|
||||
{downloads.map(i => <DownloadRow key={i.id} fetchDownloads={fetchDownloads} {...i}/>)}
|
||||
</TableBody>
|
||||
</Table>;
|
||||
} else {
|
||||
return <Placeholder>
|
||||
<PlaceholderLine/>
|
||||
<PlaceholderLine/>
|
||||
</Placeholder>;
|
||||
</Table>
|
||||
} else if (downloads) {
|
||||
return <Segment>No downloads are scheduled.</Segment>
|
||||
} else if (downloads === undefined) {
|
||||
return <ErrorMessage>Unable to fetch downloads</ErrorMessage>
|
||||
}
|
||||
return <Placeholder>
|
||||
<PlaceholderLine/>
|
||||
<PlaceholderLine/>
|
||||
</Placeholder>
|
||||
}
|
||||
|
||||
export function DownloadsPage() {
|
||||
|
|
|
|||
|
|
@ -2,8 +2,7 @@ import React from "react";
|
|||
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 {APIButton, ErrorMessage, 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";
|
||||
|
|
@ -155,6 +154,7 @@ export class SettingsPage extends React.Component {
|
|||
}, this.handleHotspotChange);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
this.setState({ready: undefined});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -207,6 +207,8 @@ export class SettingsPage extends React.Component {
|
|||
render() {
|
||||
if (this.state.ready === false) {
|
||||
return <Loader active inline='centered'/>
|
||||
} else if (this.state.ready === undefined) {
|
||||
return <ErrorMessage>Unable to fetch settings</ErrorMessage>
|
||||
}
|
||||
|
||||
let {
|
||||
|
|
@ -224,124 +226,120 @@ export class SettingsPage extends React.Component {
|
|||
|
||||
const qrButton = <Button icon style={{marginBottom: '1em'}}><Icon name='qrcode' size='big'/></Button>;
|
||||
|
||||
return <ThemeContext.Consumer>
|
||||
{({i, t}) => <Container fluid>
|
||||
<WROLModeMessage content='Settings are disabled because WROL Mode is enabled.'/>
|
||||
return <Container fluid>
|
||||
<WROLModeMessage content='Settings are disabled because WROL Mode is enabled.'/>
|
||||
|
||||
<Segment>
|
||||
<HotspotToggle/>
|
||||
<ThrottleToggle/>
|
||||
</Segment>
|
||||
<Segment>
|
||||
<HotspotToggle/>
|
||||
<ThrottleToggle/>
|
||||
</Segment>
|
||||
|
||||
<Segment>
|
||||
<Header as='h2'>
|
||||
Settings
|
||||
</Header>
|
||||
<p {...t}>
|
||||
Any changes will be written to <i>config/wrolpi.yaml</i>.
|
||||
</p>
|
||||
<Segment>
|
||||
<Header as='h2'>
|
||||
Settings
|
||||
</Header>
|
||||
<p>Any changes will be written to <i>config/wrolpi.yaml</i>.</p>
|
||||
|
||||
<Form id="settings" onSubmit={this.handleSubmit}>
|
||||
<div style={{margin: '0.5em'}}>
|
||||
<Toggle
|
||||
label='Download on Startup'
|
||||
disabled={disabled || download_on_startup === null}
|
||||
checked={download_on_startup === true}
|
||||
onChange={checked => this.handleInputChange(null, 'download_on_startup', checked)}
|
||||
/>
|
||||
</div>
|
||||
<Form id="settings" onSubmit={this.handleSubmit}>
|
||||
<div style={{margin: '0.5em'}}>
|
||||
<Toggle
|
||||
label='Download on Startup'
|
||||
disabled={disabled || download_on_startup === null}
|
||||
checked={download_on_startup === true}
|
||||
onChange={checked => this.handleInputChange(null, 'download_on_startup', checked)}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div style={{margin: '0.5em'}}>
|
||||
<Toggle
|
||||
label='CPU Power-save on Startup'
|
||||
disabled={disabled || throttle_on_startup === null}
|
||||
checked={throttle_on_startup === true}
|
||||
onChange={checked => this.handleInputChange(null, 'throttle_on_startup', checked)}
|
||||
/>
|
||||
</div>
|
||||
<div style={{margin: '0.5em'}}>
|
||||
<Toggle
|
||||
label='CPU Power-save on Startup'
|
||||
disabled={disabled || throttle_on_startup === null}
|
||||
checked={throttle_on_startup === true}
|
||||
onChange={checked => this.handleInputChange(null, 'throttle_on_startup', checked)}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div style={{margin: '0.5em'}}>
|
||||
<Toggle
|
||||
label='Ignore outdated Zims'
|
||||
disabled={disabled || ignore_outdated_zims === null}
|
||||
checked={ignore_outdated_zims === true}
|
||||
onChange={checked => this.handleInputChange(null, 'ignore_outdated_zims', checked)}
|
||||
/>
|
||||
</div>
|
||||
<div style={{margin: '0.5em'}}>
|
||||
<Toggle
|
||||
label='Ignore outdated Zims'
|
||||
disabled={disabled || ignore_outdated_zims === null}
|
||||
checked={ignore_outdated_zims === true}
|
||||
onChange={checked => this.handleInputChange(null, 'ignore_outdated_zims', checked)}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<FormGroup inline>
|
||||
<FormInput
|
||||
label={<>
|
||||
<b {...t}>Download Timeout</b>
|
||||
<HelpPopup content='Downloads will be stopped after this many seconds have elapsed.
|
||||
<FormGroup inline>
|
||||
<FormInput
|
||||
label={<>
|
||||
<b>Download Timeout</b>
|
||||
<HelpPopup content='Downloads will be stopped after this many seconds have elapsed.
|
||||
Downloads will never timeout if this is empty.'/>
|
||||
</>}
|
||||
value={download_timeout}
|
||||
disabled={disabled || download_timeout === null}
|
||||
onChange={(e, d) => this.handleTimeoutChange(e, 'download_timeout', d.value)}
|
||||
/>
|
||||
</FormGroup>
|
||||
</>}
|
||||
value={download_timeout}
|
||||
disabled={disabled || download_timeout === null}
|
||||
onChange={(e, d) => this.handleTimeoutChange(e, 'download_timeout', d.value)}
|
||||
/>
|
||||
</FormGroup>
|
||||
|
||||
<FormGroup inline>
|
||||
<FormInput
|
||||
label='Hotspot SSID'
|
||||
value={hotspot_ssid}
|
||||
disabled={disabled || hotspot_ssid === null}
|
||||
onChange={(e, d) => this.setState({hotspot_ssid: d.value}, this.handleHotspotChange)}
|
||||
/>
|
||||
<FormInput
|
||||
label='Hotspot Password'
|
||||
disabled={disabled || hotspot_password === null}
|
||||
value={hotspot_password}
|
||||
onChange={(e, d) => this.setState({hotspot_password: d.value}, this.handleHotspotChange)}
|
||||
/>
|
||||
<FormInput
|
||||
label='Hotspot Device'
|
||||
disabled={disabled || hotspot_password === null}
|
||||
value={hotspot_device}
|
||||
onChange={(e, d) => this.handleInputChange(e, 'hotspot_device', d.value)}
|
||||
/>
|
||||
</FormGroup>
|
||||
<FormGroup inline>
|
||||
<FormInput
|
||||
label='Hotspot SSID'
|
||||
value={hotspot_ssid}
|
||||
disabled={disabled || hotspot_ssid === null}
|
||||
onChange={(e, d) => this.setState({hotspot_ssid: d.value}, this.handleHotspotChange)}
|
||||
/>
|
||||
<FormInput
|
||||
label='Hotspot Password'
|
||||
disabled={disabled || hotspot_password === null}
|
||||
value={hotspot_password}
|
||||
onChange={(e, d) => this.setState({hotspot_password: d.value}, this.handleHotspotChange)}
|
||||
/>
|
||||
<FormInput
|
||||
label='Hotspot Device'
|
||||
disabled={disabled || hotspot_password === null}
|
||||
value={hotspot_device}
|
||||
onChange={(e, d) => this.handleInputChange(e, 'hotspot_device', d.value)}
|
||||
/>
|
||||
</FormGroup>
|
||||
|
||||
<Modal closeIcon
|
||||
onClose={() => this.setState({qrOpen: false})}
|
||||
onOpen={this.handleQrOpen}
|
||||
open={this.state.qrOpen}
|
||||
trigger={qrButton}
|
||||
>
|
||||
<ModalHeader>
|
||||
Scan this code to join the hotspot
|
||||
</ModalHeader>
|
||||
<ModalContent>
|
||||
<div style={{display: 'inline-block', backgroundColor: '#ffffff', padding: '1em'}}>
|
||||
<QRCode value={qrCodeValue} size={300}/>
|
||||
</div>
|
||||
</ModalContent>
|
||||
</Modal>
|
||||
<Modal closeIcon
|
||||
onClose={() => this.setState({qrOpen: false})}
|
||||
onOpen={this.handleQrOpen}
|
||||
open={this.state.qrOpen}
|
||||
trigger={qrButton}
|
||||
>
|
||||
<ModalHeader>
|
||||
Scan this code to join the hotspot
|
||||
</ModalHeader>
|
||||
<ModalContent>
|
||||
<div style={{display: 'inline-block', backgroundColor: '#ffffff', padding: '1em'}}>
|
||||
<QRCode value={qrCodeValue} size={300}/>
|
||||
</div>
|
||||
</ModalContent>
|
||||
</Modal>
|
||||
|
||||
<br/>
|
||||
<br/>
|
||||
|
||||
<APIButton
|
||||
color='violet'
|
||||
size='big'
|
||||
onClick={this.handleSubmit}
|
||||
obeyWROLMode={true}
|
||||
disabled={disabled}
|
||||
>Save</APIButton>
|
||||
<APIButton
|
||||
color='violet'
|
||||
size='big'
|
||||
onClick={this.handleSubmit}
|
||||
obeyWROLMode={true}
|
||||
disabled={disabled}
|
||||
>Save</APIButton>
|
||||
|
||||
<Dimmer active={pending}>
|
||||
<Loader active={pending} size='large'/>
|
||||
</Dimmer>
|
||||
<Dimmer active={pending}>
|
||||
<Loader active={pending} size='large'/>
|
||||
</Dimmer>
|
||||
|
||||
</Form>
|
||||
</Segment>
|
||||
</Form>
|
||||
</Segment>
|
||||
|
||||
<Segment>
|
||||
<Header as='h3'>Control WROLPi</Header>
|
||||
<RestartButton/>
|
||||
<ShutdownButton/>
|
||||
</Segment>
|
||||
</Container>}
|
||||
</ThemeContext.Consumer>
|
||||
<Segment>
|
||||
<Header as='h3'>Control WROLPi</Header>
|
||||
<RestartButton/>
|
||||
<ShutdownButton/>
|
||||
</Segment>
|
||||
</Container>
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -196,6 +196,13 @@ export function StatusPage() {
|
|||
memoryPercent = Math.round(memory_stats['used'] / memory_stats['total'] * 100);
|
||||
}
|
||||
|
||||
const SizedHeader = ({children}) => {
|
||||
return <div style={{marginBottom: '1em'}}>
|
||||
<Media at='mobile'><Header as='h1'>{children}</Header></Media>
|
||||
<Media greaterThanOrEqual='tablet'><Header as='h2'>{children}</Header></Media>
|
||||
</div>
|
||||
}
|
||||
|
||||
return <>
|
||||
<Media at='mobile'>
|
||||
<Segment>
|
||||
|
|
@ -212,22 +219,6 @@ export function StatusPage() {
|
|||
<LoadStatistic label='15 Minute Load' value={minute_15} cores={cores}/>
|
||||
</StatisticGroup>
|
||||
</Segment>
|
||||
|
||||
<Segment>
|
||||
<Header as='h1'>Drive Bandwidth</Header>
|
||||
{disk_bandwidth.map((disk) => <DiskBandwidth key={disk['name']} {...disk}/>)}
|
||||
</Segment>
|
||||
|
||||
<Segment>
|
||||
<Header as='h1'>Network Bandwidth</Header>
|
||||
{bandwidth ? bandwidth.map(i => <BandwidthProgressGroup key={i['name']} bandwidth={i}/>) :
|
||||
<ProgressPlaceholder/>}
|
||||
</Segment>
|
||||
|
||||
<Segment>
|
||||
<Header as='h1'>Drive Usage</Header>
|
||||
{drives.map((drive) => <DriveInfo key={drive['mount']} {...drive}/>)}
|
||||
</Segment>
|
||||
</Media>
|
||||
<Media greaterThanOrEqual='tablet'>
|
||||
<Segment>
|
||||
|
|
@ -245,22 +236,25 @@ export function StatusPage() {
|
|||
<LoadStatistic label='15 Min.' value={minute_15} cores={cores}/>
|
||||
</StatisticGroup>
|
||||
</Segment>
|
||||
|
||||
<Segment>
|
||||
<Header as='h2'>Drive Bandwidth</Header>
|
||||
{disk_bandwidth.map(disk => <DiskBandwidth key={disk['name']} {...disk}/>)}
|
||||
</Segment>
|
||||
|
||||
<Segment>
|
||||
<Header as='h2'>Network Bandwidth</Header>
|
||||
{bandwidth ? bandwidth.map(i => <BandwidthProgressGroup key={i['name']} bandwidth={i}/>) :
|
||||
<ProgressPlaceholder/>}
|
||||
</Segment>
|
||||
|
||||
<Segment>
|
||||
<Header as='h2'>Drive Usage</Header>
|
||||
{drives.map(drive => <DriveInfo key={drive['mount']} {...drive}/>)}
|
||||
</Segment>
|
||||
</Media>
|
||||
|
||||
<Segment>
|
||||
<SizedHeader>Drive Bandwidth</SizedHeader>
|
||||
{disk_bandwidth && disk_bandwidth.length > 0 ? disk_bandwidth.map((disk) => <DiskBandwidth
|
||||
key={disk['name']} {...disk}/>)
|
||||
: <ProgressPlaceholder/>}
|
||||
</Segment>
|
||||
|
||||
<Segment>
|
||||
<SizedHeader>Network Bandwidth</SizedHeader>
|
||||
{bandwidth ? bandwidth.map(i => <BandwidthProgressGroup key={i['name']} bandwidth={i}/>)
|
||||
: <ProgressPlaceholder/>}
|
||||
</Segment>
|
||||
|
||||
<Segment>
|
||||
<SizedHeader>Drive Usage</SizedHeader>
|
||||
{drives && drives.length > 0 ? drives.map((drive) => <DriveInfo key={drive['mount']} {...drive}/>)
|
||||
: <ProgressPlaceholder/>}
|
||||
</Segment>
|
||||
</>
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue