import React from "react"; import { useRouter } from "next/router"; import { formatRelative } from "date-fns"; import CellData from "./CellData"; import ModData from "./ModData"; import PluginData from "./PluginData"; import DataDirPicker from "./DataDirPicker"; import PluginTxtEditor from "./PluginTxtEditor"; import PluginsList from "./PluginsList"; 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; }; const Sidebar: React.FC = ({ selectedCell, clearSelectedCell, setSelectedCells, counts, countsError, open, setOpen, lastModified, }) => { 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) => { 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 renderOpenSidebar = () => { if (selectedCell) { return (

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

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

Modmapper

An interactive map of Skyrim mods.

{lastModified && (
Last updated:{" "} {formatRelative(new Date(lastModified), new Date())}
)}
); } }; const onClose = () => { clearSelectedCell(); }; return ( <> {!open ? ( ) : ( )} {renderOpenSidebar()} ); }; export default Sidebar;