import { CookiesLockedMessage, ErrorMessage, LoadStatistic, PageContainer, RefreshHeader, SearchResultsInput, useLocalStorage, useTitle } from "./components/Common"; import React, {useContext, useState} from "react"; import {useHotkeys} from "react-hotkeys-hook"; import {Media, SettingsContext, StatusContext} from "./contexts/contexts"; import {DownloadMenu} from "./components/Download"; import { ActionInput, Button, ButtonGroup, Divider, Header, Icon, Message, Modal, Panel, Stack, Statistic, StatisticGroup, } from "./components/ui"; import {Link, useNavigate, useSearchParams} from "react-router"; import {BandwidthProgressCombined, CPUUsageProgress} from "./components/admin/Status"; import {ProgressPlaceholder} from "./components/Placeholder"; import {refreshFiles} from "./api"; import _ from "lodash"; import {TagsDashboard} from "./Tags"; import {UploadModal} from "./components/Upload"; import {SearchView, useSearch, useSearchSuggestions} from "./components/Search"; import {OutdatedZimsMessage} from "./components/Zim"; import {useSearchFilter, useSearchRecentFiles, useWROLMode} from "./hooks/customHooks"; import {ExtensionInstallSuggestion} from "./components/admin/ExtensionInstallSuggestion"; import {fileMimetypeFilterOptions, FileCards, SearchFilterButton} from "./components/Files"; import {useCalculators} from "./components/Calculators"; import {classifyAndEvaluate} from "./components/calculators/mathConfig"; // A spinning refresh glyph, used as the `icon` for the "files are being refreshed" Message. const RefreshingIcon = (props) => ; export function FlagsMessages() { const {settings, fetchSettings} = React.useContext(SettingsContext); const {status} = useContext(StatusContext); if (_.isEmpty(status?.flags)) { return <> } const flags = status['flags']; let refreshingMessage; let refreshRequiredMessage; // Do not tell the maintainer to refresh the files if the FileWorker is busy. if (flags.file_worker_busy) { // FileWorker is busy. refreshingMessage =

Click here to view the progress

; } else if (!flags.refresh_complete) { // `refresh_complete` flag is not set. Tell the maintainer to refresh the files. refreshRequiredMessage = { e.preventDefault(); refreshFiles(); }}>Click here to refresh all your files. ; } let dbDownMessage; if (!flags.db_up) { dbDownMessage = Database is down

API is unable to connect to the database. Check the server logs.

} let internetDownMessage; if (!flags.have_internet && !settings.wrol_mode) { internetDownMessage = No Internet

WROLPi has no Internet. Downloads will not start.

; } let mediaUnmountedMessage; if (flags.media_mounted === false) { mediaUnmountedMessage = No drive mounted

WROLPi has no media drive mounted for one or more storage locations. Downloads would write to the root filesystem and can fill it. {' '}Open the Controller to mount a drive.

; } return <> {refreshingMessage} {dbDownMessage || refreshRequiredMessage} {mediaUnmountedMessage} {settings && settings['ignore_outdated_zims'] === false && flags.outdated_zims ? : null} {internetDownMessage} } function EvaluateForm() { const helpContents =

Enter an equation or a value with units.

Math:
2 + 3
sqrt(15)
8 * pi
Unit Conversions:
15 km to miles
65 degF to degC
1 gallon to liters
5 psi to atm
Auto-Convert (enter value + unit):
5 miles
100 degF
1 gallon
500 Wh
Radiation:
0.5 Sv
1 Gy to raddose
100 remdose to Sv
Data:
7 * 750 Mb
2 Tb to Gb
const [showMessage, setShowMessage] = React.useState(false); const [inputValue, setInputValue] = React.useState(''); const [evaluatedValue, setEvaluatedValue] = React.useState(helpContents); const doEvaluate = () => { if (!inputValue) { setEvaluatedValue(helpContents); return; } setEvaluatedValue(''); // Clear input temporarily so the user can tell something happened. try { const {primary, conversions} = classifyAndEvaluate(inputValue); setEvaluatedValue(
{primary} {conversions.length > 0 &&
Also: {conversions.map((c, i) =>
{c}
)}
}
); } catch (error) { console.error(error); setEvaluatedValue(`Unable to evaluate: ${error.message}`); } } return
{ e.preventDefault(); doEvaluate(); }}> setShowMessage(true)} onChange={(e) => setInputValue(e.currentTarget.value)} action={} /> {showMessage && {evaluatedValue} } } function DashboardCalculators() { const {calculatorLinks} = useCalculators(); return
Calculators
{calculatorLinks}
} export function Getters() { const {status} = useContext(StatusContext); const wrolModeEnabled = useWROLMode(); // Getters are Downloads or Uploads. const [selectedGetter, setSelectedGetter] = useState(null); const gettersDisabled = status?.flags?.refresh_complete !== true; // Deep-link support: the WROLPi browser extension (and anyone else) can open // /?downloader=&download_url=&download_url= // to auto-open the download modal pre-filled with a downloader and URLs. const [searchParams, setSearchParams] = useSearchParams(); const initialDownloader = searchParams.get('downloader'); const initialUrls = searchParams.getAll('download_url'); React.useEffect(() => { if (initialDownloader && selectedGetter !== 'downloads') { setSelectedGetter('downloads'); } // Run once on mount per change to query params. // eslint-disable-next-line react-hooks/exhaustive-deps }, [initialDownloader]); const handleSetGetter = (e, value) => { if (e) { e.preventDefault(); } setSelectedGetter(value); // Closing the modal? Clear deep-link params so a refresh doesn't re-open. if (value === null && (initialDownloader || initialUrls.length)) { const next = new URLSearchParams(searchParams); next.delete('downloader'); next.delete('download_url'); setSearchParams(next, {replace: true}); } } const getter =
Or
{status?.flags && gettersDisabled &&

Download and Upload are available after your files are refreshed.

}
; let getterModal; if (selectedGetter === 'downloads') { getterModal = handleSetGetter(null, null)} > Download from the Internet ; } else if (selectedGetter === 'upload') { // The same dialog the file browser opens; it asks for a destination because, unlike the // browser, the dashboard has no selected directory to upload into. getterModal = handleSetGetter(null, null)} disabled={gettersDisabled} />; } if (wrolModeEnabled) { return <> } return <> {getter} {getterModal} } export function DashboardStatus() { const {status} = useContext(StatusContext); let percent = 0; let load = {}; let cores = 0; let pending_downloads = '?'; if (status && status['cpu_stats']) { percent = status['cpu_stats']['percent']; load = status['load_stats']; cores = status['cpu_stats']['cores']; } const {downloads} = status; if (!_.isEmpty(downloads)) { pending_downloads = downloads && downloads['disabled'] ? 'x' : downloads['pending']; } let bandwidths = ; if (status && status['nic_bandwidth_stats']) { bandwidths = Object.entries(status['nic_bandwidth_stats']) .map(([name, bandwidth]) => ); } else if (window.apiDown) { // apiDown is set in useStatus bandwidths = null; } return {/* * The panel is a link, but it should not read as one. * * `a` takes `color: var(--blue)` and an underline on hover from tokens.css, and a * statistic's value sets no color of its own -- so the three load figures inherited * the link color, and crossing the panel underlined them together. The same pair * every card title uses says "this text belongs to what contains it": the pointer * cursor still comes from the UA stylesheet, which is the affordance that matters. */}
Status
Bandwidth
{bandwidths}
; } function DashboardRecentFiles() { // Show only the files the user is part way through. const [continueOnly, setContinueOnly] = useLocalStorage('dashboard_recent_continue', false); const {searchFiles, loading, fetchFiles} = useSearchRecentFiles(continueOnly); let files = ; if (continueOnly && searchFiles && searchFiles.length === 0) { files =

Nothing in progress. A video, audio file, ebook or comic you stop part way through will be here.

; } return
{files}
} export function DashboardPage() { const navigate = useNavigate(); const searchInputRef = React.useRef(); useHotkeys('f', (e) => { e.preventDefault(); if (searchInputRef.current) { searchInputRef.current.focus(); } }, {enableOnFormTags: false}); // The search the user submitted. const {searchStr, setSearchStr, activeTags, isEmpty, anyTag} = useSearch(); // The search that the user is typing. const [localSearchStr, setLocalSearchStr] = React.useState(searchStr); const { suggestions, suggestionsResults, suggestionsSums, handleResultSelect, resultRenderer, loading, setSearchStr: setSuggestionSearchStr, setSearchTags, clearDate, } = useSearchSuggestions(searchStr, activeTags, anyTag); React.useEffect(() => { setSuggestionSearchStr(localSearchStr); }, [localSearchStr]); React.useEffect(() => { setLocalSearchStr(searchStr); }, [searchStr]); React.useEffect(() => { if (activeTags) { setSearchTags(activeTags); } }, [JSON.stringify(activeTags)]); let title = 'Dashboard'; if (searchStr) { title = `Search: ${searchStr} - Dashboard`; } else if (activeTags && activeTags.length === 1) { title = `Tag: ${activeTags[0]} - Dashboard`; } else if (activeTags && activeTags.length > 1) { const tagNames = activeTags.join(' & '); title = `Tags: ${tagNames} - Dashboard`; } useTitle(title); // Only show dashboard parts if not searching. let body = ; if (searchStr || (activeTags && activeTags.length > 0)) { // User has submitted and wants full search. body = ; } const {setFilter} = useSearchFilter(); const clearAllSearch = () => { clearDate(); setFilter(null); setSearchStr(null); navigate('/'); } const getSearchResultsInput = (props) => { return ; }; // The search input grows to fill the row; the Filter button sits immediately after it. Flexbox adapts // to the client width, so only the control size changes between mobile and larger screens. const searchRow = (big) => { const inputProps = {style: {flexGrow: 1, minWidth: 0, marginBottom: 0}}; if (big) { inputProps.size = 'big'; } /* * No `marginBottom`. This row is a top-level block of the dashboard, so its own 2em was * added to the page stack's gap -- 52.8px below the search box against 17.6px between * every other pair of blocks, on the most-looked-at page in the app. One source of * spacing, and it is the stack. */ return
{getSearchResultsInput(inputProps)}
; }; return {searchRow(false)} {searchRow(true)} {!searchStr && } {!searchStr && } {body} }