import React, { useEffect, useState } from "react"; import { useRouter } from "next/router"; import useSWRImmutable from "swr/immutable"; import CellData from "./CellData"; import ModData from "./ModData"; import styles from "../styles/Sidebar.module.css"; import { render } from "react-dom"; interface Cell { x: number; y: number; form_id: number; } type Props = { selectedCell: { x: number; y: number } | null; clearSelectedCell: () => void; setSelectedCells: (cells: { x: number; y: number }[] | null) => void; map: React.MutableRefObject; counts: Record | null; countsError: Error | null; }; const Sidebar: React.FC = ({ selectedCell, clearSelectedCell, setSelectedCells, counts, countsError, map, }) => { 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 onClose = () => { clearSelectedCell(); }; 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 { return null; } }; export default Sidebar;