/* eslint-disable @next/next/no-img-element */ import React, { useEffect } 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(); useEffect(() => { document.getElementById("sidebar")?.scrollTo(0, 0); }, [selectedCell, router.query.mod, router.query.plugin]); 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 ( ); } 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 ( ); } else if (router.query.plugin) { return ( ); } else { return ( ); } }; const onClose = () => { clearSelectedCell(); }; return ( <> {!open ? ( ) : ( )} {renderOpenSidebar()} ); }; export default Sidebar;