diff --git a/app/src/components/Archive.js b/app/src/components/Archive.js index 92a659dc..8a5071d5 100644 --- a/app/src/components/Archive.js +++ b/app/src/components/Archive.js @@ -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 = ; - if (!isEmpty(history)) { - historyList = ; - } else if (isEmpty(history)) { + if (history && history.length === 0) { historyList =

No history available

; + } else if (history) { + historyList = ; } 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 <> - ) - } else if (isEmpty(domains)) { + ; + } else if (_.isEmpty(domains)) { return No domains yet. Archive some webpages! @@ -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 =
invertSelection()} - disabled={isEmpty(archives)} + disabled={_.isEmpty(archives)} > Invert diff --git a/app/src/components/Channels.js b/app/src/components/Channels.js index 8b8df634..57b5fd50 100644 --- a/app/src/components/Channels.js +++ b/app/src/components/Channels.js @@ -19,7 +19,6 @@ import { DirectoryInput, frequencyOptions, humanFileSize, - isEmpty, isoDatetimeToString, RequiredAsterisk, secondsToFrequency, @@ -547,7 +546,7 @@ export function Channels() { - } else if (isEmpty(channels)) { + } else if (_.isEmpty(channels)) { return <> {header} diff --git a/app/src/components/Common.js b/app/src/components/Common.js index effdf187..6e271bfd 100644 --- a/app/src/components/Common.js +++ b/app/src/components/Common.js @@ -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 (
; } + let body = + + + ; + if (_.isArray(browseFiles)) { + body = <>} // Hide the preview that the 3rd party provided. + />; + } + return <> {clearButton} {buttons}
- <>} // Hide the preview that the 3rd party provided. - /> + {body}
} @@ -291,12 +300,12 @@ function FileCard({file}) { } export function FileCards({files}) { - if (!isEmpty(files)) { + if (!_.isEmpty(files)) { return {files.map(i => )} } else if (files && files.length === 0) { - return
No files found.
+ return No results! } else { return } @@ -379,7 +388,13 @@ function FileRow({file}) { } export function FileTable({files, selectOn, onSelect, footer, selectedKeys}) { - if (!isEmpty(files)) { + if (!files) { + return + + + + + } else if (files && files.length > 0) { const headerContents = ['Poster', 'Title']; const rows = files.map(i => ); return ; - } else if (isEmpty(files)) { - return

No results!

} else { - return - - - - + return

No results!

} } @@ -472,8 +481,7 @@ export function FilesView({ if (view === 'list') { const footer = selectOn && selectElem ? <> - - {selectElem} + {selectElem} : null; body = ; diff --git a/app/src/components/Inventory.js b/app/src/components/Inventory.js index 859a8435..1c962e95 100644 --- a/app/src/components/Inventory.js +++ b/app/src/components/Inventory.js @@ -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() { } - if (!isEmpty(byCategory)) { + if (!_.isEmpty(byCategory)) { return @@ -77,7 +77,7 @@ function InventorySummary() { } - if (!isEmpty(bySubcategory)) { + if (!_.isEmpty(bySubcategory)) { return
@@ -106,7 +106,7 @@ function InventorySummary() { } - if (!isEmpty(byName)) { + if (!_.isEmpty(byName)) { return
@@ -309,7 +309,7 @@ class InventoryList extends React.Component { } render() { - if (isEmpty(this.props.items)) { + if (_.isEmpty(this.props.items)) { return {({t}) => (

Add some items using the form above!

@@ -386,7 +386,7 @@ class InventoryList extends React.Component { diff --git a/app/src/components/Map.js b/app/src/components/Map.js index dda22e1c..c3bf25e3 100644 --- a/app/src/components/Map.js +++ b/app/src/components/Map.js @@ -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 = ; let rows; @@ -219,7 +220,7 @@ class ManageMap extends React.Component { ; - } else if (isEmpty(files)) { + } else if (_.isEmpty(files)) { rows = No PBF map files were found in map/pbf ; diff --git a/app/src/components/Tables.js b/app/src/components/Tables.js index 66de30cf..7241012e 100644 --- a/app/src/components/Tables.js +++ b/app/src/components/Tables.js @@ -5,7 +5,6 @@ import React from "react"; export function SelectableTable({headerContents, selectOn, onSelect, selectedKeys, footer, rows}) { footer = footer ? - {selectOn && } {footer} : null; diff --git a/app/src/components/Theme.js b/app/src/components/Theme.js index c1207ee6..536ff983 100644 --- a/app/src/components/Theme.js +++ b/app/src/components/Theme.js @@ -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!'); } diff --git a/app/src/components/Videos.js b/app/src/components/Videos.js index 165e3987..7a9f0960 100644 --- a/app/src/components/Videos.js +++ b/app/src/components/Videos.js @@ -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 =
invertSelection()} - disabled={isEmpty(videos)} + disabled={_.isEmpty(videos)} > Invert diff --git a/app/src/components/admin/Downloads.js b/app/src/components/admin/Downloads.js index 0cdba1ac..36fe95b5 100644 --- a/app/src/components/admin/Downloads.js +++ b/app/src/components/admin/Downloads.js @@ -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 =

No downloads are scheduled.

+ if (_.isEmpty(onceDownloads)) { + onceTable = No downloads are scheduled. } else if (onceDownloads) { onceTable = ( <> @@ -364,8 +364,8 @@ export function Downloads() { } let recurringTable = tablePlaceholder; - if (isEmpty(recurringDownloads)) { - recurringTable =

No recurring downloads are scheduled.

+ if (_.isEmpty(recurringDownloads)) { + recurringTable = No recurring downloads are scheduled. } else if (recurringDownloads) { recurringTable =
{nonStoppableHeader} diff --git a/app/src/hooks/customHooks.js b/app/src/hooks/customHooks.js index 87b73871..e2638a95 100644 --- a/app/src/hooks/customHooks.js +++ b/app/src/hooks/customHooks.js @@ -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 () => {