/* eslint-disable @next/next/no-img-element */ import React from "react"; import { useRouter } from "next/router"; import { formatRelative } from "date-fns"; import arrow from "../public/img/arrow.svg"; import close from "../public/img/close.svg"; import AddModDialog from "./AddModDialog"; import CellData from "./CellData"; import ModData from "./ModData"; import PluginDetail from "./PluginDetail"; import DataDirPicker from "./DataDirPicker"; import PluginTxtEditor from "./PluginTxtEditor"; import ParsedPluginsList from "./ParsedPluginsList"; import FetchedPluginsList from "./FetchedPluginsList"; import styles from "../styles/Sidebar.module.css"; type Props = { selectedCell: { x: number; y: number } | null; clearSelectedCell: () => void; setSelectedCells: (cells: { x: number; y: number }[] | null) => void; counts: Record | null; countsError: Error | null; open: boolean; setOpen: (open: boolean) => void; lastModified: string | null | undefined; onSelectFile: (fileId: number) => void; onSelectPlugin: (hash: string) => void; }; const Sidebar: React.FC = ({ selectedCell, clearSelectedCell, setSelectedCells, counts, countsError, open, setOpen, lastModified, onSelectFile, onSelectPlugin, }) => { const router = useRouter(); const renderLoadError = (error: Error) => (
{`Error loading live download counts: ${error.message}`}
); const renderLoading = () =>
Loading...
; const renderCellData = (selectedCell: { x: number; y: number }) => { if (countsError) return renderLoadError(countsError); if (!counts) return renderLoading(); return ; }; const renderModData = ( selectedMod: number, selectedFile: number, selectedPlugin: string ) => { if (countsError) return renderLoadError(countsError); if (!counts) return renderLoading(); return ( ); }; const renderPluginData = (plugin: string) => { if (countsError) return renderLoadError(countsError); if (!counts) return renderLoading(); return ; }; const renderLastModified = (lastModified: string | null | undefined) => { if (lastModified) { return (
Site last updated:{" "} {formatRelative(new Date(lastModified), new Date())}
); } }; const renderOpenSidebar = () => { if (selectedCell) { return (

Cell {selectedCell.x}, {selectedCell.y}

{renderCellData(selectedCell)} {renderLastModified(lastModified)}
); } else if (router.query.mod) { const modId = parseInt(router.query.mod as string, 10); const fileId = parseInt(router.query.file as string, 10); const pluginHash = router.query.plugin as string; return (
{!Number.isNaN(modId) && renderModData(modId, fileId, pluginHash)} {renderLastModified(lastModified)}
); } else if (router.query.plugin) { return (
{renderPluginData( typeof router.query.plugin === "string" ? router.query.plugin : router.query.plugin[0] )} {renderLastModified(lastModified)}
); } else { return (

Modmapper

An interactive map of Skyrim mods.

{renderLastModified(lastModified)}
); } }; const onClose = () => { clearSelectedCell(); }; return ( <> {!open ? ( ) : ( )} {renderOpenSidebar()} ); }; export default Sidebar;