/* eslint-disable @next/next/no-img-element */ import React, { useEffect } from "react"; import { useRouter } from "next/router"; import { formatRelative } from "date-fns"; 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; 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, open, setOpen, lastModified, onSelectFile, onSelectPlugin, }) => { const router = useRouter(); useEffect(() => { document.getElementById("sidebar")?.scrollTo(0, 0); }, [selectedCell, router.query.mod, router.query.plugin]); 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) { if (!router.query.game) { router.replace(`/?game=skyrimspecialedition&mod=${router.query.mod}`); return null; } const game = typeof router.query.game === "string" ? router.query.game : router.query.game[0]; 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;