/* 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 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 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); return (
{!Number.isNaN(modId) && renderModData(modId)} {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;