import {useOutdatedZims, useSearchZim, useWROLMode} from "../hooks/customHooks"; import React, {useState} from "react"; import { APIButton, encodeMediaPath, ErrorMessage, HandPointMessage, humanFileSize, IframeViewer, InfoMessage, normalizeEstimate, PageContainer, Paginator, TabLinks, TagIcon, Toggle, useTitle, WarningMessage } from "./Common"; import { Accordion, Button, Divider, Group, Header, Label, Loading, Message, Modal, Panel, Placeholder, Select, Table, toast, } from "./ui"; import {TextPlaceholder} from "./Placeholder"; import {TagsSelector} from "../Tags"; import {AddToPlaylistButton} from "./AddToPlaylist"; import { deleteOutdatedZims, fetchZims, fetchZimSubscriptions, refreshFiles, saveSettings, setZimAutoSearch, tagZimEntry, untagZimEntry, zimSubscribe, zimUnsubscribe } from "../api"; import {useSearch} from "./Search"; import {TagsQuerySelector} from "./Files"; import {Link, Route, Routes} from "react-router"; import {SortableTable} from "./SortableTable"; import _ from "lodash"; import {ZIM_VIEWER_URI} from "./Vars"; import {HeadlineText} from "./Headline"; export const OutdatedZimsMessage = ({onClick}) => { const [open, setOpen] = React.useState(false); const {outdated, current} = useOutdatedZims(); const onClose = () => setOpen(false); const handleDelete = async () => { try { const success = await deleteOutdatedZims(); if (success) { toast({ type: 'info', title: 'Zims deleted', description: 'Outdated Zims have been deleted.', time: 5000, }); } else { toast({ type: 'error', title: 'Failed to delete Zims', description: 'Outdated Zims have NOT been deleted. See server logs.', time: 5000, }); } } finally { onClose(); } } const handleIgnore = async () => { const config = {ignore_outdated_zims: true}; await saveSettings(config); if (onClick) { await onClick(); } } let modalContent = ; if (outdated && outdated.length > 0) { modalContent = <>
To Delete
{outdated.map(i =>
{i}
)}
To Keep
{current.map(i =>
{i}
)} } return New Zim files have been downloaded. Outdated Zim files can be removed.

{modalContent} Delete Ignore Forever
} const ZimSearchEntry = ({zimId, onTag, onUntag, entry}) => { const {path, title, headline, tag_names} = entry; const [open, setOpen] = React.useState(false); const url = `/api/zim/${zimId}/entry/${encodeMediaPath(path)}`; const handleClick = async (e) => { if (e) { e.preventDefault(); } setOpen(true); } const localAddTag = (name) => { onTag(zimId, path, name); } const localUntag = (name) => { onUntag(zimId, path, name); } const tagIcon = tag_names && tag_names.length > 0 ? : null; return
'} closeTag={''}/> {tagIcon}
setOpen(false)}>
]*>/g, '')}} content={null} title='Add to Playlist'/>
} const ZimAccordionItem = ({value, active, data, searchStr, activeTags}) => { const {id, estimate, metadata} = data; const {title, date} = metadata; const {zim, fetchSearch, pages, loading} = useSearchZim(searchStr, id, active, activeTags); const localAddTag = async (zimId, path, name) => { await tagZimEntry(zimId, path, name); await fetchSearch(); } const localUntag = async (zimId, path, name) => { await untagZimEntry(zimId, path, name); await fetchSearch(); } let body = ; if (zim && !loading) { const {search} = zim; if (search && search.length > 0) { body = search.map(i =>
); } else { body =

No results

; } } const paginator =
; const label = ; return
{title} {label}
{date}
{body} {paginator}
} const ZimsRefreshWarning = () => { return
Click here to refresh all your files.
; } export const ZimSearchView = ({suggestions, loading}) => { const [activeValue, setActiveValue] = React.useState(null); const {searchStr, activeTags, setTags} = useSearch(); const {zimsEstimates} = suggestions; let body; if (!_.isEmpty(zimsEstimates)) { body = {zimsEstimates.map(i => )} ; } else if (loading) { body = ; } else if (_.isEmpty(zimsEstimates)) { body = ; } return <> setTags(i)}/> {body} } const DownloadMessage = () => { return

More Zim files are available from the full Kiwix library  https://download.kiwix.org/

} const ViewerMessage = () => { return

You can view your Zim files using the Kiwix app, or at {ZIM_VIEWER_URI}

} export const ZimCatalogItemRow = ({item, subscriptions, iso_639_codes, fetchSubscriptions}) => { const {name, languages, size} = item; const subscription = name in subscriptions ? subscriptions[name] : null; const subscriptionLanguage = subscription ? subscription['language'] : 'en'; const [language, setLanguage] = useState(subscriptionLanguage); const [pending, setPending] = useState(false); const languageChange = subscription ? language !== subscription['language'] : false; const wrolModeEnabled = useWROLMode(); const handleButton = async () => { let success = false; try { setPending(true); if (subscription && !languageChange) { success = await zimUnsubscribe(subscription['id']); } else { success = await zimSubscribe(name, language); } } catch (e) { console.error(e); } setPending(false); if (!success) { toast({ type: 'error', title: 'Error!', description: subscription ? 'Failed to unsubscribe' : 'Failed to subscribe', }) } if (fetchSubscriptions) { await fetchSubscriptions(); } } /* * The code itself when the API's table has no name for it. * * `iso_639_codes` covers 639-1 and 639-2; the Kiwix catalog also carries 639-3 codes and * locale variants -- `ami`, `ary`, `arz`, `be-tarask` -- and 89 of the codes in the * catalog on a live WROLPi are absent from its 672-entry table. Each of those produced * `label: undefined`, and a `searchable` Mantine Select calls `option.label.toLowerCase()` * while building its dropdown on mount, before anyone opens it. One unnamed language * anywhere in the catalog therefore took the whole /zim/manage page down. * * The code rather than a blank: a user choosing which language to subscribe to has to be * able to tell one unnamed language from another, and the code is all we know. * * `iso_639_codes` is also null on first render -- ManageZim initialises it that way and * fills it from the API -- so it is read defensively too. */ const languageOptions = languages.map(i => { return {value: i, label: (iso_639_codes && iso_639_codes[i]) || i} }); const languageDropdown =