import {LoadStatistic, PageContainer, SearchInput, useTitle} from "./components/Common";
import React, {useContext, useState} from "react";
import {Media, StatusContext} from "./contexts/contexts";
import {DownloadMenu} from "./components/Download";
import {
Button,
Divider,
Header,
Modal,
ModalContent,
ModalHeader,
Segment,
Statistic,
StatisticGroup
} from "./components/Theme";
import {Link, useNavigate} from "react-router-dom";
import {BandwidthProgressCombined, CPUUsageProgress} from "./components/admin/Status";
import {ProgressPlaceholder} from "./components/Placeholder";
import {GridColumn, GridRow, Icon, 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} from "./components/Search";
import {KiwixRestartMessage, OutdatedZimsMessage} from "./components/Zim";
import {useSettings, useWROLMode} from "./hooks/customHooks";
import {FileSearchFilterButton} from "./components/Files";
function FlagsMessages({flags}) {
const {settings, fetchSettings} = useSettings();
if (!flags) {
return <>>
}
let refreshing;
let refreshRequired;
let dbDown;
let kiwixRestart;
// Do not tell the maintainer to refresh the files if they are already refreshing.
if (flags.indexOf('refreshing') >= 0) {
// Actively refreshing.
refreshing = Your files are being refreshed.
Click here to view the progress
;
} else if (flags.indexOf('refresh_complete') === -1) {
// `refresh_complete` flag is not set. Tell the maintainer to refresh the files.
refreshRequired = Refresh requiredClick here to refresh all your files.
;
}
if (flags.indexOf('kiwix_restart') >= 0) {
kiwixRestart = ;
}
if (flags.indexOf('db_up') === -1) {
dbDown = Database is down
API is unable to connect to the database. Check the server logs.
}
return <>
{refreshing}
{dbDown || refreshRequired}
{settings && settings['ignore_outdated_zims'] === false && flags.indexOf('outdated_zims') >= 0 ?
: null}
{kiwixRestart}
>
}
export function Getters() {
const {status} = useContext(StatusContext);
const wrolModeEnabled = useWROLMode();
// Getters are Downloads or Uploads.
const [selectedGetter, setSelectedGetter] = useState(null);
const gettersDisabled = status?.flags?.indexOf('refresh_complete') === -1;
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}
>
}
export function DashboardPage() {
const navigate = useNavigate();
const {searchStr, setSearchStr, activeTags} = useSearch();
const {status} = useContext(StatusContext);
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 = ;
}
return navigate('/')}
style={{marginBottom: '2em'}}
/>
navigate('/')}
style={{marginBottom: '2em'}}
/>
{!searchStr && }
{body}
}
function DashboardStatus() {
const {status} = useContext(StatusContext);
let percent = 0;
let load = {};
let cores = 0;
let pending_downloads = '?';
if (status && status['cpu_info']) {
percent = status['cpu_info']['percent'];
load = status['load'];
cores = status['cpu_info']['cores'];
}
const {downloads} = status;
if (!_.isEmpty(downloads)) {
pending_downloads = downloads && downloads['disabled'] ? 'x' : downloads['pending'];
}
let bandwidths = ;
if (status && status['bandwidth']) {
bandwidths = status['bandwidth'].map(i => );
}
return StatusBandwidth
{bandwidths}
;
}