mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-11-20 23:16:17 -05:00
Reworking empty-states for all pages and tables. Removing custom isEmpty in favor of lodash.
This commit is contained in:
parent
78aa6bfd1d
commit
0621cd184d
11 changed files with 82 additions and 87 deletions
|
|
@ -18,13 +18,13 @@ import {
|
|||
} from "semantic-ui-react";
|
||||
import {
|
||||
BackButton,
|
||||
CardLink, cardTitleWrapper,
|
||||
CardLink,
|
||||
cardTitleWrapper,
|
||||
defaultSearchOrder,
|
||||
isoDatetimeToString,
|
||||
ExternalCardLink,
|
||||
FileIcon,
|
||||
HelpHeader,
|
||||
isEmpty,
|
||||
isoDatetimeToString,
|
||||
mimetypeColor,
|
||||
PageContainer,
|
||||
SearchInput,
|
||||
|
|
@ -116,10 +116,10 @@ function ArchivePage() {
|
|||
</>);
|
||||
|
||||
let historyList = <Loader active/>;
|
||||
if (!isEmpty(history)) {
|
||||
historyList = <FileCards files={history}/>;
|
||||
} else if (isEmpty(history)) {
|
||||
if (history && history.length === 0) {
|
||||
historyList = <p>No history available</p>;
|
||||
} else if (history) {
|
||||
historyList = <FileCards files={history}/>;
|
||||
}
|
||||
|
||||
const domain = archive.domain ? archive.domain.domain : null;
|
||||
|
|
@ -229,16 +229,16 @@ export function Domains() {
|
|||
const [domains] = useDomains();
|
||||
const [searchStr, setSearchStr] = useState('');
|
||||
|
||||
if (domains === null) {
|
||||
return (<>
|
||||
if (!domains) {
|
||||
return <>
|
||||
<Placeholder>
|
||||
<PlaceholderHeader>
|
||||
<PlaceholderLine/>
|
||||
<PlaceholderLine/>
|
||||
</PlaceholderHeader>
|
||||
</Placeholder>
|
||||
</>)
|
||||
} else if (isEmpty(domains)) {
|
||||
</>;
|
||||
} else if (_.isEmpty(domains)) {
|
||||
return <Message>
|
||||
<Message.Header>No domains yet.</Message.Header>
|
||||
<Message.Content>Archive some webpages!</Message.Content>
|
||||
|
|
@ -292,7 +292,7 @@ function Archives() {
|
|||
useTitle('Archives');
|
||||
|
||||
let filterOptions = [];
|
||||
if (!isEmpty(domains)) {
|
||||
if (!_.isEmpty(domains)) {
|
||||
domains.forEach(i => {
|
||||
filterOptions = [...filterOptions, {text: i['domain'], key: i['domain'], value: i['domain']}]
|
||||
});
|
||||
|
|
@ -382,7 +382,7 @@ function Archives() {
|
|||
const selectElm = <div style={{marginTop: '0.5em'}}>
|
||||
<Button
|
||||
color='red'
|
||||
disabled={isEmpty(selectedArchives)}
|
||||
disabled={_.isEmpty(selectedArchives)}
|
||||
onClick={() => setDeleteOpen(true)}
|
||||
>Delete</Button>
|
||||
<Confirm
|
||||
|
|
@ -395,14 +395,14 @@ function Archives() {
|
|||
<Button
|
||||
color='grey'
|
||||
onClick={() => invertSelection()}
|
||||
disabled={isEmpty(archives)}
|
||||
disabled={_.isEmpty(archives)}
|
||||
>
|
||||
Invert
|
||||
</Button>
|
||||
<Button
|
||||
color='yellow'
|
||||
onClick={() => clearSelection()}
|
||||
disabled={isEmpty(archives) || isEmpty(selectedArchives)}
|
||||
disabled={_.isEmpty(archives) || _.isEmpty(selectedArchives)}
|
||||
>
|
||||
Clear
|
||||
</Button>
|
||||
|
|
|
|||
|
|
@ -19,7 +19,6 @@ import {
|
|||
DirectoryInput,
|
||||
frequencyOptions,
|
||||
humanFileSize,
|
||||
isEmpty,
|
||||
isoDatetimeToString,
|
||||
RequiredAsterisk,
|
||||
secondsToFrequency,
|
||||
|
|
@ -547,7 +546,7 @@ export function Channels() {
|
|||
</TableBody>
|
||||
</Table>
|
||||
</>
|
||||
} else if (isEmpty(channels)) {
|
||||
} else if (_.isEmpty(channels)) {
|
||||
return <>
|
||||
{header}
|
||||
<Message>
|
||||
|
|
|
|||
|
|
@ -307,16 +307,6 @@ export function arraysEqual(a, b) {
|
|||
return true;
|
||||
}
|
||||
|
||||
export function isEmpty(i) {
|
||||
const str = Object.prototype.toString.call(i);
|
||||
if (str === '[object Object]') {
|
||||
return Object.keys(i).length === 0;
|
||||
} else if (str === '[object Array]') {
|
||||
return i.length === 0;
|
||||
}
|
||||
return !i;
|
||||
}
|
||||
|
||||
export function scrollToTop() {
|
||||
window.scrollTo({
|
||||
top: 0, behavior: "auto"
|
||||
|
|
@ -588,8 +578,7 @@ export function mimetypeColor(mimetype) {
|
|||
return 'green'
|
||||
} else if (mimetype && mimetype.startsWith('application/zip')) {
|
||||
return 'purple'
|
||||
} else if (mimetype && (
|
||||
mimetype.startsWith('application/epub') || mimetype.startsWith('application/x-mobipocket-ebook'))) {
|
||||
} else if (mimetype && (mimetype.startsWith('application/epub') || mimetype.startsWith('application/x-mobipocket-ebook'))) {
|
||||
return 'yellow'
|
||||
}
|
||||
} catch (e) {
|
||||
|
|
@ -748,10 +737,7 @@ export function DirectoryInput({disabled, error, placeholder, setInput, value, r
|
|||
return (<div>
|
||||
<Input
|
||||
action={{
|
||||
color: error ? 'red' : 'green',
|
||||
labelPosition: 'left',
|
||||
icon: 'folder',
|
||||
content: media_directory,
|
||||
color: error ? 'red' : 'green', labelPosition: 'left', icon: 'folder', content: media_directory,
|
||||
}}
|
||||
required={required}
|
||||
disabled={disabled}
|
||||
|
|
|
|||
|
|
@ -21,17 +21,18 @@ import 'react-keyed-file-browser/dist/react-keyed-file-browser.css';
|
|||
import {deleteFile, refreshDirectoryFiles, refreshFiles} from "../api";
|
||||
import {
|
||||
CardGroupCentered,
|
||||
CardPosterLink, cardTitleWrapper,
|
||||
isoDatetimeToString,
|
||||
CardLink,
|
||||
CardPosterLink,
|
||||
cardTitleWrapper,
|
||||
ExternalCardLink,
|
||||
FileIcon,
|
||||
humanFileSize,
|
||||
isEmpty,
|
||||
isoDatetimeToString,
|
||||
mimetypeColor,
|
||||
PageContainer,
|
||||
Paginator,
|
||||
textEllipsis,
|
||||
useTitle, CardLink
|
||||
useTitle
|
||||
} from "./Common";
|
||||
import {useBrowseFiles, useQuery, useSearchFiles} from "../hooks/customHooks";
|
||||
import {Route, Routes} from "react-router-dom";
|
||||
|
|
@ -129,21 +130,29 @@ export function Files() {
|
|||
buttons = <FilesRefreshButton/>;
|
||||
}
|
||||
|
||||
let body = <Placeholder>
|
||||
<PlaceholderLine/>
|
||||
<PlaceholderLine/>
|
||||
</Placeholder>;
|
||||
if (_.isArray(browseFiles)) {
|
||||
body = <FileBrowser
|
||||
showActionBar={false}
|
||||
canFilter={false}
|
||||
files={browseFiles}
|
||||
icons={icons}
|
||||
onFolderOpen={handleFolderChange}
|
||||
onFolderClose={handleFolderChange}
|
||||
onSelect={onSelect}
|
||||
detailRenderer={() => <></>} // Hide the preview that the 3rd party provided.
|
||||
/>;
|
||||
}
|
||||
|
||||
return <>
|
||||
{clearButton}
|
||||
{buttons}
|
||||
<Divider/>
|
||||
<div {...t}>
|
||||
<FileBrowser
|
||||
showActionBar={false}
|
||||
canFilter={false}
|
||||
files={browseFiles}
|
||||
icons={icons}
|
||||
onFolderOpen={handleFolderChange}
|
||||
onFolderClose={handleFolderChange}
|
||||
onSelect={onSelect}
|
||||
detailRenderer={() => <></>} // Hide the preview that the 3rd party provided.
|
||||
/>
|
||||
{body}
|
||||
</div>
|
||||
</>
|
||||
}
|
||||
|
|
@ -291,12 +300,12 @@ function FileCard({file}) {
|
|||
}
|
||||
|
||||
export function FileCards({files}) {
|
||||
if (!isEmpty(files)) {
|
||||
if (!_.isEmpty(files)) {
|
||||
return <CardGroupCentered>
|
||||
{files.map(i => <FileCard key={i['path']} file={i}/>)}
|
||||
</CardGroupCentered>
|
||||
} else if (files && files.length === 0) {
|
||||
return <Header as='h4'>No files found.</Header>
|
||||
return <Segment>No results!</Segment>
|
||||
} else {
|
||||
return <CardGroupCentered><CardPlacholder/></CardGroupCentered>
|
||||
}
|
||||
|
|
@ -379,7 +388,13 @@ function FileRow({file}) {
|
|||
}
|
||||
|
||||
export function FileTable({files, selectOn, onSelect, footer, selectedKeys}) {
|
||||
if (!isEmpty(files)) {
|
||||
if (!files) {
|
||||
return <Placeholder>
|
||||
<PlaceholderLine/>
|
||||
<PlaceholderLine/>
|
||||
<PlaceholderLine/>
|
||||
</Placeholder>
|
||||
} else if (files && files.length > 0) {
|
||||
const headerContents = ['Poster', 'Title'];
|
||||
const rows = files.map(i => <FileRow key={i['key']} file={i}/>);
|
||||
return <SelectableTable
|
||||
|
|
@ -390,14 +405,8 @@ export function FileTable({files, selectOn, onSelect, footer, selectedKeys}) {
|
|||
footer={footer}
|
||||
rows={rows}
|
||||
/>;
|
||||
} else if (isEmpty(files)) {
|
||||
return <Segment><p>No results!</p></Segment>
|
||||
} else {
|
||||
return <Placeholder>
|
||||
<PlaceholderLine/>
|
||||
<PlaceholderLine/>
|
||||
<PlaceholderLine/>
|
||||
</Placeholder>
|
||||
return <Segment><p>No results!</p></Segment>
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -472,8 +481,7 @@ export function FilesView({
|
|||
if (view === 'list') {
|
||||
const footer = selectOn && selectElem ?
|
||||
<>
|
||||
<TableHeaderCell/>
|
||||
<TableHeaderCell>{selectElem}</TableHeaderCell>
|
||||
<TableHeaderCell colSpan='3'>{selectElem}</TableHeaderCell>
|
||||
</> : null;
|
||||
body = <FileTable files={files} selectOn={selectOn}
|
||||
onSelect={onSelect} footer={footer} selectedKeys={selectedKeys}/>;
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ import {
|
|||
} from "semantic-ui-react";
|
||||
import {Route, Routes} from "react-router-dom";
|
||||
import {toast} from 'react-semantic-toasts';
|
||||
import {arraysEqual, enumerate, isEmpty, PageContainer, replaceNullValues, TabLinks, useTitle} from './Common';
|
||||
import {arraysEqual, enumerate, PageContainer, replaceNullValues, TabLinks, useTitle} from './Common';
|
||||
import _ from 'lodash';
|
||||
import {ThemeContext} from "../contexts/contexts";
|
||||
import {useInventory} from "../hooks/customHooks";
|
||||
|
|
@ -50,7 +50,7 @@ function InventorySummary() {
|
|||
</TableRow>
|
||||
}
|
||||
|
||||
if (!isEmpty(byCategory)) {
|
||||
if (!_.isEmpty(byCategory)) {
|
||||
return <Table>
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
|
|
@ -77,7 +77,7 @@ function InventorySummary() {
|
|||
</TableRow>
|
||||
}
|
||||
|
||||
if (!isEmpty(bySubcategory)) {
|
||||
if (!_.isEmpty(bySubcategory)) {
|
||||
return <Table>
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
|
|
@ -106,7 +106,7 @@ function InventorySummary() {
|
|||
</TableRow>
|
||||
}
|
||||
|
||||
if (!isEmpty(byName)) {
|
||||
if (!_.isEmpty(byName)) {
|
||||
|
||||
return <Table>
|
||||
<TableHeader>
|
||||
|
|
@ -309,7 +309,7 @@ class InventoryList extends React.Component {
|
|||
}
|
||||
|
||||
render() {
|
||||
if (isEmpty(this.props.items)) {
|
||||
if (_.isEmpty(this.props.items)) {
|
||||
return <ThemeContext.Consumer>
|
||||
{({t}) => (
|
||||
<p {...t}>Add some items using the form above!</p>
|
||||
|
|
@ -386,7 +386,7 @@ class InventoryList extends React.Component {
|
|||
<Button
|
||||
color='red'
|
||||
onClick={this.handleRemove}
|
||||
disabled={isEmpty(this.state.checkboxes)}
|
||||
disabled={_.isEmpty(this.state.checkboxes)}
|
||||
floated='right'
|
||||
>
|
||||
Remove
|
||||
|
|
@ -394,7 +394,7 @@ class InventoryList extends React.Component {
|
|||
<Button
|
||||
secondary
|
||||
onClick={this.handleSave}
|
||||
disabled={isEmpty(this.state.checkboxes)}
|
||||
disabled={_.isEmpty(this.state.checkboxes)}
|
||||
>
|
||||
Save
|
||||
</Button>
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import React, {useContext} from "react";
|
||||
import {HelpPopup, humanFileSize, isEmpty, PageContainer, TabLinks, useTitle, WROLModeMessage} from "./Common";
|
||||
import {HelpPopup, humanFileSize, PageContainer, TabLinks, useTitle, WROLModeMessage} from "./Common";
|
||||
import {Route, Routes} from "react-router-dom";
|
||||
import {getMapImportStatus, importMapFiles} from "../api";
|
||||
import {
|
||||
|
|
@ -18,6 +18,7 @@ import {
|
|||
import Message from "semantic-ui-react/dist/commonjs/collections/Message";
|
||||
import {Button, Loader, Placeholder, Table} from "./Theme";
|
||||
import {StatusContext} from "../contexts/contexts";
|
||||
import _ from "lodash";
|
||||
|
||||
function DockerMapImportWarning() {
|
||||
const {status} = useContext(StatusContext);
|
||||
|
|
@ -137,7 +138,7 @@ class ManageMap extends React.Component {
|
|||
|
||||
this.setState({'ready': false});
|
||||
const {files, selectedPaths} = this.state;
|
||||
if (isEmpty(selectedPaths)) {
|
||||
if (_.isEmpty(selectedPaths)) {
|
||||
// No files are selected, import all.
|
||||
let paths = [];
|
||||
for (let i = 0; i < files.length; i++) {
|
||||
|
|
@ -198,13 +199,13 @@ class ManageMap extends React.Component {
|
|||
pending.length > 1 ? 'Importing...' : `Importing ${pending[0]}`
|
||||
: null;
|
||||
|
||||
let disabled = dockerized || isEmpty(files) || import_running;
|
||||
let disabled = dockerized || _.isEmpty(files) || import_running;
|
||||
let importButton = <Button
|
||||
primary
|
||||
disabled={disabled}
|
||||
onClick={this.import}
|
||||
>
|
||||
{!isEmpty(selectedPaths) ? 'Import Selected' : 'Import All'}
|
||||
{!_.isEmpty(selectedPaths) ? 'Import Selected' : 'Import All'}
|
||||
</Button>;
|
||||
|
||||
let rows;
|
||||
|
|
@ -219,7 +220,7 @@ class ManageMap extends React.Component {
|
|||
</Placeholder>
|
||||
</TableCell>
|
||||
</TableRow>;
|
||||
} else if (isEmpty(files)) {
|
||||
} else if (_.isEmpty(files)) {
|
||||
rows = <TableRow>
|
||||
<TableCell/><TableCell colSpan={5}>No PBF map files were found in <b>map/pbf</b></TableCell>
|
||||
</TableRow>;
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ import React from "react";
|
|||
export function SelectableTable({headerContents, selectOn, onSelect, selectedKeys, footer, rows}) {
|
||||
footer = footer ? <TableFooter>
|
||||
<TableRow>
|
||||
{selectOn && <TableHeaderCell/>}
|
||||
{footer}
|
||||
</TableRow>
|
||||
</TableFooter> : null;
|
||||
|
|
|
|||
|
|
@ -23,7 +23,8 @@ import {
|
|||
TabPane as TAB_PANE,
|
||||
TextArea as TEXTAREA
|
||||
} from "semantic-ui-react";
|
||||
import {ColorToSemanticHexColor, isEmpty} from "./Common";
|
||||
import {ColorToSemanticHexColor} from "./Common";
|
||||
import _ from "lodash";
|
||||
|
||||
export const darkTheme = 'dark';
|
||||
export const lightTheme = 'light';
|
||||
|
|
@ -32,7 +33,7 @@ export const systemTheme = 'system';
|
|||
export const themeSessionKey = 'color-scheme';
|
||||
|
||||
export function ThemeWrapper({children, ...props}) {
|
||||
if (!isEmpty(props)) {
|
||||
if (!_.isEmpty(props)) {
|
||||
console.log(props);
|
||||
console.error('ThemeWrapper does not support props!');
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,13 +2,13 @@ import React, {Fragment, useContext, useEffect, useState} from 'react';
|
|||
import {Link, Route, Routes, useParams} from "react-router-dom";
|
||||
import {
|
||||
CardLink,
|
||||
CardPosterLink, cardTitleWrapper,
|
||||
CardPosterLink,
|
||||
cardTitleWrapper,
|
||||
defaultSearchOrder,
|
||||
defaultVideoOrder,
|
||||
Duration,
|
||||
isoDatetimeToString,
|
||||
FileIcon,
|
||||
isEmpty,
|
||||
isoDatetimeToString,
|
||||
mimetypeColor,
|
||||
PageContainer,
|
||||
scrollToTop,
|
||||
|
|
@ -40,6 +40,7 @@ import Icon from "semantic-ui-react/dist/commonjs/elements/Icon";
|
|||
import {Button, Card, CardIcon, Header, Loader, Placeholder, Segment, Statistic, StatisticGroup} from "./Theme";
|
||||
import {deleteVideos} from "../api";
|
||||
import {ThemeContext} from "../contexts/contexts";
|
||||
import _ from "lodash";
|
||||
|
||||
export function VideoWrapper() {
|
||||
const {videoId} = useParams();
|
||||
|
|
@ -175,7 +176,7 @@ function VideosPage({filter}) {
|
|||
const selectElm = <div style={{marginTop: '0.5em'}}>
|
||||
<Button
|
||||
color='red'
|
||||
disabled={isEmpty(selectedVideos)}
|
||||
disabled={_.isEmpty(selectedVideos)}
|
||||
onClick={() => setDeleteOpen(true)}
|
||||
>Delete</Button>
|
||||
<Confirm
|
||||
|
|
@ -188,14 +189,14 @@ function VideosPage({filter}) {
|
|||
<Button
|
||||
color='grey'
|
||||
onClick={() => invertSelection()}
|
||||
disabled={isEmpty(videos)}
|
||||
disabled={_.isEmpty(videos)}
|
||||
>
|
||||
Invert
|
||||
</Button>
|
||||
<Button
|
||||
color='yellow'
|
||||
onClick={() => clearSelection()}
|
||||
disabled={isEmpty(videos) || isEmpty(selectedVideos)}
|
||||
disabled={_.isEmpty(videos) || _.isEmpty(selectedVideos)}
|
||||
>
|
||||
Clear
|
||||
</Button>
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@ import {clearCompletedDownloads, clearFailedDownloads, deleteDownload, killDownl
|
|||
import {Link} from "react-router-dom";
|
||||
import {
|
||||
DisableDownloadsToggle,
|
||||
isEmpty,
|
||||
isoDatetimeToElapsedPopup,
|
||||
secondsToFrequency,
|
||||
textEllipsis,
|
||||
|
|
@ -22,9 +21,10 @@ import {
|
|||
TableHeaderCell,
|
||||
TableRow
|
||||
} from "semantic-ui-react";
|
||||
import {Button, Header, Placeholder, Table} from "../Theme";
|
||||
import {Button, Header, Placeholder, Segment, Table} from "../Theme";
|
||||
import {ThemeContext} from "../../contexts/contexts";
|
||||
import {useDownloads} from "../../hooks/customHooks";
|
||||
import _ from "lodash";
|
||||
|
||||
function ClearCompleteDownloads({callback}) {
|
||||
const [disabled, setDisabled] = React.useState(false);
|
||||
|
|
@ -345,8 +345,8 @@ export function Downloads() {
|
|||
);
|
||||
|
||||
let onceTable = tablePlaceholder;
|
||||
if (isEmpty(onceDownloads)) {
|
||||
onceTable = <p {...t}>No downloads are scheduled.</p>
|
||||
if (_.isEmpty(onceDownloads)) {
|
||||
onceTable = <Segment>No downloads are scheduled.</Segment>
|
||||
} else if (onceDownloads) {
|
||||
onceTable = (
|
||||
<>
|
||||
|
|
@ -364,8 +364,8 @@ export function Downloads() {
|
|||
}
|
||||
|
||||
let recurringTable = tablePlaceholder;
|
||||
if (isEmpty(recurringDownloads)) {
|
||||
recurringTable = <p {...t}>No recurring downloads are scheduled.</p>
|
||||
if (_.isEmpty(recurringDownloads)) {
|
||||
recurringTable = <Segment>No recurring downloads are scheduled.</Segment>
|
||||
} else if (recurringDownloads) {
|
||||
recurringTable = <Table>
|
||||
{nonStoppableHeader}
|
||||
|
|
|
|||
|
|
@ -153,7 +153,7 @@ export const useSearchArchives = (defaultLimit, domain, order_by) => {
|
|||
const searchStr = searchParams.get('q') || '';
|
||||
const order = searchParams.get('order') || order_by;
|
||||
|
||||
const [archives, setArchives] = useState();
|
||||
const [archives, setArchives] = useState(null);
|
||||
const [totalPages, setTotalPages] = useState(0);
|
||||
|
||||
const localSearchArchives = async () => {
|
||||
|
|
@ -446,7 +446,7 @@ export const useSearchFiles = (defaultLimit = 48, emptySearch = false, model) =>
|
|||
}
|
||||
|
||||
export const useBrowseFiles = () => {
|
||||
const [browseFiles, setBrowseFiles] = useState([]);
|
||||
const [browseFiles, setBrowseFiles] = useState(null);
|
||||
const [openFolders, setOpenFolders] = useState([]);
|
||||
|
||||
const fetchFiles = async () => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue