Reworking default/empty/error states for all pages. Null is pending, undefined is error.

This commit is contained in:
Roland 2023-09-07 20:13:36 -06:00
parent ee95204d3b
commit 619a88c429
No known key found for this signature in database
GPG key ID: 9D6DBD3ACF11AB93
15 changed files with 294 additions and 260 deletions

View file

@ -13,7 +13,7 @@ import {
TableHeaderCell,
TableRow,
} from "semantic-ui-react";
import {APIButton, contrastingColor, scrollToTopOfElement} from "./components/Common";
import {APIButton, contrastingColor, ErrorMessage, scrollToTopOfElement} from "./components/Common";
import {
Button,
FormInput,
@ -54,8 +54,8 @@ export function useTags() {
setTags(t);
setTagNames(t.map(i => i['name']));
} catch (e) {
setTags([]);
setTagNames([]);
setTags(undefined);
setTagNames(undefined);
console.error(e);
}
}
@ -284,7 +284,7 @@ function EditTagsModal() {
</Table>
</div>
</Modal>
<Button onClick={() => setOpen(true)} color='violet'>
<Button onClick={() => setOpen(true)} color='violet' disabled={tags === undefined}>
Edit
</Button>
</>
@ -420,8 +420,10 @@ export const TagsDashboard = () => {
const {tagNames, TagsLinkGroup} = React.useContext(TagsContext);
let availableTagsGroup = <Loader active inline/>;
if (tagNames && tagNames.length) {
if (tagNames && tagNames.length >= 1) {
availableTagsGroup = <TagsLinkGroup tagNames={tagNames} style={{marginTop: '0.5em'}}/>;
} else if (tagNames === undefined) {
availableTagsGroup = <ErrorMessage>Could not fetch tags</ErrorMessage>
}
return <Segment>

View file

@ -2,7 +2,7 @@ import React, {useContext} from 'react';
import {Divider, Input, SegmentGroup, StatisticLabel, StatisticValue, TableCell, TableRow} from "semantic-ui-react";
import {Link, Route, Routes} from "react-router-dom";
import {decryptOTP, encryptOTP} from "../api";
import {APIButton, humanFileSize, mimetypeColor, PageContainer, toLocaleString, useTitle} from "./Common";
import {APIButton, ErrorMessage, humanFileSize, mimetypeColor, PageContainer, toLocaleString, useTitle} from "./Common";
import {ThemeContext} from "../contexts/contexts";
import {Button, Header, Loader, Segment, Statistic, StatisticGroup, Table, TextArea} from "./Theme";
import {useStatistics, useVINDecoder} from "../hooks/customHooks";
@ -208,8 +208,8 @@ function StatisticsPage() {
if (statistics === undefined) {
return <>
<Header as='h1'>Statistics</Header>
<Segment><p {...s}>Failed to fetch statistics</p></Segment>
</>;
<ErrorMessage>Failed to fetch statistics</ErrorMessage>
</>
}
if (statistics['global_statistics']) {

View file

@ -18,7 +18,7 @@ import {
BackButton,
CardLink,
cardTitleWrapper,
encodeMediaPath,
encodeMediaPath, ErrorMessage,
ExternalCardLink,
FileIcon,
findPosterPath,
@ -27,7 +27,6 @@ import {
isoDatetimeToString,
mimetypeColor,
PageContainer,
PreviewLink,
PreviewPath,
SearchInput,
SortButton,
@ -301,7 +300,8 @@ export function DomainsPage() {
const [domains] = useDomains();
const [searchStr, setSearchStr] = useState('');
if (!domains) {
if (domains === null) {
// Request is pending.
return <>
<Placeholder>
<PlaceholderHeader>
@ -310,7 +310,9 @@ export function DomainsPage() {
</PlaceholderHeader>
</Placeholder>
</>;
} else if (_.isEmpty(domains)) {
} else if (domains === undefined) {
return <ErrorMessage>Could not fetch domains</ErrorMessage>
} else if (domains && domains.length === 0) {
return <Message>
<Message.Header>No domains yet.</Message.Header>
<Message.Content>Archive some webpages!</Message.Content>
@ -366,25 +368,25 @@ export function SearchDomain() {
setDomain(value);
}
let domainOptions = [];
if (domains && domains.length > 0) {
const domainOptions = domains.map(i => {
domainOptions = domains.map(i => {
return {key: i['domain'], value: i['domain'], text: i['domain']}
});
return <>
<Dropdown selection search clearable fluid
placeholder='Domains'
options={domainOptions}
onChange={handleChange}
value={domain}
/>
</>
}
return <></>
return <>
<Dropdown selection search clearable fluid
placeholder='Domains'
options={domainOptions}
onChange={handleChange}
value={domain}
/>
</>
}
function ArchivesPage() {
const [selectedArchives, setSelectedArchives] = useState([]);
const [deleteOpen, setDeleteOpen] = useState(false);
useTitle('Archives');
@ -416,7 +418,6 @@ function ArchivesPage() {
}
const onDelete = async () => {
setDeleteOpen(false);
const archiveIds = archives.filter(i => selectedArchives.indexOf(i['primary_path']) >= 0)
.map(i => i['data']['id']);
await deleteArchives(archiveIds);

View file

@ -17,6 +17,7 @@ import {
APIButton,
BackButton,
DirectoryInput,
ErrorMessage,
frequencyOptions,
humanFileSize,
RequiredAsterisk,
@ -506,7 +507,7 @@ function MobileChannelRow({channel}) {
}
export function Channels() {
export function ChannelsPages() {
useTitle('Channels');
const {channels} = useChannels();
@ -552,7 +553,15 @@ export function Channels() {
{key: 'manage', text: 'Manage'},
];
if (channels === null) {
if (channels && channels.length === 0) {
return <>
{header}
<Message>
<Message.Header>No channels exist yet!</Message.Header>
<Message.Content><Link to='/videos/channel/new'>Create one.</Link></Message.Content>
</Message>
</>
} else if (channels === null) {
// Placeholders while fetching
return <>
{header}
@ -569,13 +578,10 @@ export function Channels() {
</TableBody>
</Table>
</>
} else if (_.isEmpty(channels)) {
} else if (channels === undefined) {
return <>
{header}
<Message>
<Message.Header>No channels exist yet!</Message.Header>
<Message.Content><Link to='/videos/channel/new'>Create one.</Link></Message.Content>
</Message>
<ErrorMessage>Could not fetch Channels</ErrorMessage>
</>
}

View file

@ -1404,11 +1404,27 @@ export function APIButton({
return button;
}
export function InfoMessage({children}) {
return <Message info icon>
export function InfoMessage({children, size = null}) {
return <Message info icon size={size}>
<SIcon name='question'/>
<Message.Content>
{children}
</Message.Content>
</Message>
}
}
export function WarningMessage({children, size = null}) {
return <Message warning icon size={size}>
<SIcon name='hand point right'/>
<Message.Content>
{children}
</Message.Content>
</Message>
}
export function ErrorMessage({children, size = null}) {
return <Message error icon size={size}>
<SIcon name='exclamation'/>
<Message.Content>{children}</Message.Content>
</Message>
}

View file

@ -11,7 +11,7 @@ import {
TableHeaderCell,
TableRow
} from "semantic-ui-react";
import {APIButton, DirectorySearch, FileIcon, humanFileSize} from "./Common";
import {APIButton, DirectorySearch, ErrorMessage, FileIcon, humanFileSize} from "./Common";
import React, {useEffect, useState} from "react";
import {deleteFile, makeDirectory, movePaths, renamePath} from "../api";
import _ from 'lodash';
@ -129,7 +129,6 @@ function Path({path, onFolderClick, onFileClick, sortData, selectedPaths, onSele
export function FileBrowser() {
const [selectedPaths, setSelectedPaths] = React.useState([]);
const [deleteOpen, setDeleteOpen] = React.useState(false);
const [renameOpen, setRenameOpen] = React.useState(false);
const [moveOpen, setMoveOpen] = React.useState(false);
const [makeDirectoryOpen, setMakeDirectoryOpen] = React.useState(false);
@ -178,7 +177,6 @@ export function FileBrowser() {
}
const reset = async () => {
setDeleteOpen(false);
setSelectedPaths([]);
setPending(true);
try {
@ -268,6 +266,8 @@ export function FileBrowser() {
<PlaceholderLine/>
<PlaceholderLine/>
</Placeholder>;
} else if (browseFiles === undefined) {
return <ErrorMessage>Could not fetch files</ErrorMessage>
}
return <>

View file

@ -18,6 +18,7 @@ import {
CardPoster,
cardTitleWrapper,
encodeMediaPath,
ErrorMessage,
ExternalCardLink,
FileIcon,
findPosterPath,
@ -37,14 +38,15 @@ import {
useQuery,
useSearchFiles,
useSearchFilter,
useSearchView, useStatusFlag,
useSearchView,
useStatusFlag,
useWROLMode
} from "../hooks/customHooks";
import {Route, Routes} from "react-router-dom";
import {CardPlaceholder} from "./Placeholder";
import {ArchiveCard, ArchiveRowCells} from "./Archive";
import Grid from "semantic-ui-react/dist/commonjs/collections/Grid";
import {Media, StatusContext, ThemeContext} from "../contexts/contexts";
import {Media, ThemeContext} from "../contexts/contexts";
import {
Button,
Card,
@ -60,7 +62,6 @@ import {
} from "./Theme";
import {SelectableTable} from "./Tables";
import {VideoCard, VideoRowCells} from "./Videos";
import _ from 'lodash';
import {FileBrowser} from "./FileBrowser";
import {refreshFiles} from "../api";
import {useSubscribeEventName} from "../Events";
@ -161,15 +162,17 @@ function FileCard({file}) {
}
export function FileCards({files}) {
if (!_.isEmpty(files)) {
if (files && files.length >= 1) {
return <CardGroupCentered>
{files.map(i => <FileCard key={i['primary_path']} file={i}/>)}
</CardGroupCentered>
} else if (files && files.length === 0) {
return <Segment>No results!</Segment>
} else {
return <CardGroupCentered><CardPlaceholder/></CardGroupCentered>
} else if (files === undefined) {
return <ErrorMessage>Could not search!</ErrorMessage>
}
// Response is pending.
return <CardGroupCentered><CardPlaceholder/></CardGroupCentered>
}
function ImageRowCells({file}) {
@ -246,13 +249,7 @@ function FileRow({file}) {
}
export function FileTable({files, selectOn, onSelect, footer, selectedKeys}) {
if (!files) {
return <Placeholder>
<PlaceholderLine/>
<PlaceholderLine/>
<PlaceholderLine/>
</Placeholder>
} else if (files && files.length > 0) {
if (files && files.length > 0) {
const headerContents = ['Poster', 'Title'];
const rows = files.map(i => <FileRow key={i['key']} file={i}/>);
return <SelectableTable
@ -263,9 +260,17 @@ export function FileTable({files, selectOn, onSelect, footer, selectedKeys}) {
footer={footer}
rows={rows}
/>;
} else {
} else if (files) {
return <Segment>No results!</Segment>
} else if (files === undefined) {
return <ErrorMessage>Could not search!</ErrorMessage>
}
return <Placeholder>
<PlaceholderLine/>
<PlaceholderLine/>
<PlaceholderLine/>
</Placeholder>
}
export function FileRowTagIcon({file}) {

View file

@ -1,6 +1,7 @@
import React, {useContext} from "react";
import {
APIButton,
ErrorMessage,
HelpPopup,
humanFileSize,
InfoMessage,
@ -136,6 +137,7 @@ class ManageMap extends React.Component {
});
} catch (e) {
console.error(e);
this.setState({files: undefined});
}
}
@ -216,24 +218,27 @@ class ManageMap extends React.Component {
{!_.isEmpty(selectedPaths) ? 'Import Selected' : 'Import All'}
</APIButton>;
let rows;
if (!files) {
// Fetch request is not complete.
rows = <TableRow>
<TableCell/>
<TableCell colSpan={6}>
<Placeholder>
<PlaceholderLine/>
<PlaceholderLine/>
</Placeholder>
</TableCell>
</TableRow>;
} else if (_.isEmpty(files)) {
let rows = <TableRow>
<TableCell/>
<TableCell colSpan={6}>
<Placeholder>
<PlaceholderLine/>
<PlaceholderLine/>
</Placeholder>
</TableCell>
</TableRow>;
if (files && files.length === 0) {
rows = <TableRow>
<TableCell/><TableCell colSpan={5}>No PBF map files were found in <b>map/pbf</b></TableCell>
</TableRow>;
} else {
} else if (files && files.length >= 1) {
rows = files.map(i => this.tableRow(i, disabled));
} else if (files === undefined) {
rows = <TableRow>
<TableCell colSpan={6}>
<ErrorMessage>Could not fetch map files</ErrorMessage>
</TableCell>
</TableRow>
}
let spaceHelpPopup = <HelpPopup

View file

@ -9,6 +9,7 @@ import {
defaultVideoOrder,
Duration,
encodeMediaPath,
ErrorMessage,
FileIcon,
findPosterPath,
isoDatetimeToString,
@ -35,7 +36,7 @@ import {
StatisticValue,
TableCell
} from "semantic-ui-react";
import {Channels, EditChannel, NewChannel} from "./Channels";
import {ChannelsPages, EditChannel, NewChannel} from "./Channels";
import {useChannel, useQuery, useSearchVideos, useVideo, useVideoStatistics} from "../hooks/customHooks";
import {FileRowTagIcon, FilesView} from "./Files";
import Grid from "semantic-ui-react/dist/commonjs/collections/Grid";
@ -210,16 +211,20 @@ function VideosPage() {
</>
}
function Statistics() {
function VideosStatistics() {
useTitle('Video Statistics');
const {statistics} = useVideoStatistics();
const {videos, historical, channels} = statistics;
if (!videos) {
if (statistics === null) {
// Request is pending.
return <Loader active inline='centered'/>
} else if (statistics === undefined) {
return <ErrorMessage>Unable to fetch Video Statistics</ErrorMessage>
}
const {videos, historical, channels} = statistics;
const videoNames = [
{key: 'videos', label: 'Videos'},
{key: 'sum_size', label: 'Total Size'},
@ -270,8 +275,8 @@ export function VideosRoute(props) {
<TabLinks links={links}/>
<Routes>
<Route path='/' exact element={<VideosPage/>}/>
<Route path='channel' exact element={<Channels/>}/>
<Route path='statistics' exact element={<Statistics/>}/>
<Route path='channel' exact element={<ChannelsPages/>}/>
<Route path='statistics' exact element={<VideosStatistics/>}/>
<Route path='channel/new' exact element={<NewChannel/>}/>
<Route path='channel/:channelId/edit' exact element={<EditChannel/>}/>
<Route path='channel/:channelId/video' exact element={<VideosPage/>}/>

View file

@ -31,6 +31,7 @@ import React, {useContext, useState} from "react";
import {
APIButton,
encodeMediaPath,
ErrorMessage,
humanFileSize,
InfoMessage,
normalizeEstimate,
@ -38,7 +39,8 @@ import {
Paginator,
TabLinks,
TagIcon,
useTitle
useTitle,
WarningMessage
} from "./Common";
import Grid from "semantic-ui-react/dist/commonjs/collections/Grid";
import {TagsSelector} from "../Tags";
@ -400,10 +402,10 @@ class ManageZim extends React.Component {
constructor(props) {
super(props);
this.state = {
catalog: undefined,
iso_639_codes: undefined,
subscriptions: undefined,
zims: undefined,
catalog: null,
iso_639_codes: null,
subscriptions: null,
zims: null,
}
}
@ -418,6 +420,7 @@ class ManageZim extends React.Component {
this.setState({zims});
} catch (e) {
console.error(e);
this.setState({zims: undefined}); // Display error.
}
}
@ -427,6 +430,7 @@ class ManageZim extends React.Component {
this.setState({subscriptions, catalog, iso_639_codes});
} catch (e) {
console.error(e);
this.setState({subscriptions: undefined, catalog: undefined}); // Display error.
}
}
@ -452,19 +456,19 @@ class ManageZim extends React.Component {
<PlaceholderLine/>
</PlaceholderHeader>
</Placeholder>;
if (zims && zims.length > 0) {
if (zims && zims.length >= 1) {
zimFilesBody = <SortableTable
data={zims}
rowFunc={this.zimFileTableRow}
rowKey='path'
tableHeaders={zimFilesHeaders}
/>;
} else if (zims === null || (zims && zims.length === 0)) {
zimFilesBody = <Message icon warning>
<Message.Content>
You have not subscribed to any Kiwix projects, or your files have not been refreshed.
</Message.Content>
</Message>;
} else if (zims && zims.length === 0) {
zimFilesBody = <WarningMessage>
You have not subscribed to any Kiwix projects, or your files have not been refreshed.
</WarningMessage>;
} else if (zims === undefined) {
zimFilesBody = <ErrorMessage>Could not fetch Zim files</ErrorMessage>;
}
const kiwixCatalogHeaders = [
@ -496,6 +500,8 @@ class ManageZim extends React.Component {
rowKey='name'
tableHeaders={kiwixCatalogHeaders}
/>
} else if (catalog === undefined) {
kiwixCatalog = <ErrorMessage>Could not fetch catalog</ErrorMessage>;
}
return <PageContainer>

View file

@ -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() {

View file

@ -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>
}
}

View file

@ -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>
</>
}

View file

@ -121,7 +121,7 @@ export const useDomains = () => {
setDomains(domains);
setTotal(total);
} catch (e) {
setDomains([]);
setDomains(undefined); // Display error.
setTotal(0);
}
}
@ -214,7 +214,7 @@ export const useSearchArchives = (defaultLimit) => {
description: 'Could not get archives',
time: 5000,
});
setArchives([]);
setArchives(undefined); // Could not get Archives, display error.
}
}
@ -256,7 +256,7 @@ export const useSearchVideos = (defaultLimit, channelId, order_by) => {
const {view} = useSearchView();
const headline = view === 'headline';
const [videos, setVideos] = useState();
const [videos, setVideos] = useState(null);
const [totalPages, setTotalPages] = useState(0);
const localSearchVideos = async () => {
@ -268,13 +268,7 @@ export const useSearchVideos = (defaultLimit, channelId, order_by) => {
setTotalPages(calculateTotalPages(total, limit));
} catch (e) {
console.error(e);
toast({
type: 'error',
title: 'Unexpected server response',
description: 'Could not get videos',
time: 5000,
});
setVideos([]);
setVideos(undefined);// Could not get Videos, display error.
}
}
@ -405,12 +399,7 @@ export const useChannels = () => {
setChannels(c);
} catch (e) {
console.error(e);
toast({
type: 'error',
title: 'Unexpected server response',
description: 'Could not get channels',
time: 5000,
});
setChannels(undefined); // Could not get Channels, display error.
}
}
@ -482,7 +471,7 @@ export const useBrowseFiles = () => {
setBrowseFiles(files);
} catch (e) {
console.log(e);
setBrowseFiles([]);
setBrowseFiles(undefined); // Display error.
}
}
@ -561,6 +550,10 @@ export const useDownloads = () => {
setPendingOnceDownloads(data['pending_once_downloads']);
} catch (e) {
console.error(e);
// Display errors.
setOnceDownloads(undefined);
setRecurringDownloads(undefined);
setPendingOnceDownloads(undefined);
}
}
@ -753,7 +746,7 @@ export const useCPUTemperature = () => {
export const useVideoStatistics = () => {
const [statistics, setStatistics] = useState({});
const [statistics, setStatistics] = useState(null);
const fetchStatistics = async () => {
try {
@ -765,6 +758,7 @@ export const useVideoStatistics = () => {
setStatistics(stats);
} catch (e) {
console.error(e);
setStatistics(undefined); // Display error.
}
}

View file

@ -412,7 +412,7 @@ async def get_bandwidth_info() -> Tuple[List[NICBandwidthInfo], List[DiskBandwid
try:
maximum_read_ps = max(disk['bytes_read_ps'], MAX_DISKS_BANDWIDTH[name]['maximum_read_ps'])
maximum_write_ps = max(disk['bytes_write_ps'], MAX_DISKS_BANDWIDTH[name]['maximum_write_ps'])
except KeyError as e:
except KeyError:
# Use a low first value. Hopefully all drives are capable of this speed.
maximum_read_ps = 500_000
maximum_write_ps = 500_000