import { CookiesLockedMessage, ErrorMessage, LoadStatistic, PageContainer, RefreshHeader, SearchResultsInput, useTitle } from "./components/Common"; import React, {useContext, useState} from "react"; import {Media, SettingsContext, StatusContext} from "./contexts/contexts"; import {DownloadMenu} from "./components/Download"; import { Button, Divider, Form, Header, Modal, Segment, Statistic } from "./components/Theme"; import {Link, useNavigate} from "react-router"; import {BandwidthProgressCombined, CPUUsageProgress} from "./components/admin/Status"; import {ProgressPlaceholder} from "./components/Placeholder"; import {GridColumn, GridRow, Icon, Input, Message} from "semantic-ui-react"; import Grid from "semantic-ui-react/dist/commonjs/collections/Grid"; import {refreshFiles} from "./api"; import _ from "lodash"; import {TagsDashboard} from "./Tags"; import {Upload} from "./components/Upload"; import {SearchView, useSearch, useSearchSuggestions} from "./components/Search"; import {OutdatedZimsMessage} from "./components/Zim"; import {useSearchFilter, useSearchRecentFiles, useWROLMode} from "./hooks/customHooks"; import {FileCards, FileSearchFilterButton} from "./components/Files"; import {DateSelectorButton} from "./components/DatesSelector"; import {useCalculators} from "./components/Calculators"; import {evaluate} from "mathjs"; 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 = Your files are being refreshed.

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 = Refresh required 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. ; } return <> {refreshingMessage} {dbDownMessage || refreshRequiredMessage} {settings && settings['ignore_outdated_zims'] === false && flags.outdated_zims ? : null} {internetDownMessage} } function EvaluateForm() { const helpContents =

Enter an equation above.

Examples:
2 + 3
sqrt(15)
15 km to miles
65 degF to degC
7 * 750 Mb
8 * pi
const inputRef = React.useRef(); 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 { setEvaluatedValue(evaluate(inputValue).toString()); } catch (error) { console.error(error); setEvaluatedValue(`Unable to evaluate: ${error.message}`); } } return
setShowMessage(true)} onChange={(e, {value}) => setInputValue(value)} action={} /> {showMessage && Result {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; const handleSetGetter = (e, value) => { if (e) { e.preventDefault(); } setSelectedGetter(value); } const getter = Or ; let getterModal; if (selectedGetter === 'downloads') { getterModal = handleSetGetter(null, null)} > Download from the Internet ; } else if (selectedGetter === 'upload') { getterModal = handleSetGetter(null, null)} > Upload from your device ; } if (wrolModeEnabled) { return <> } return <> {getter} {getterModal} } 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
Status
Bandwidth
{bandwidths}
; } function DashboardRecentFiles() { const {searchFiles, loading, fetchFiles} = useSearchRecentFiles(); return } export function DashboardPage() { const navigate = useNavigate(); // 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, months, dateRange, setDates, 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 ; }; return {getSearchResultsInput()} {getSearchResultsInput({size: 'big'})} {getSearchResultsInput({size: 'big'})} {!searchStr && } {body} }