2022-01-19 06:06:19 +00:00
|
|
|
import React from "react";
|
2022-01-16 07:26:17 +00:00
|
|
|
|
2022-01-19 06:06:19 +00:00
|
|
|
import CellData from "./CellData";
|
2022-01-16 07:26:17 +00:00
|
|
|
import styles from "../styles/Sidebar.module.css";
|
|
|
|
|
2022-01-19 06:06:19 +00:00
|
|
|
interface Cell {
|
|
|
|
x: number;
|
|
|
|
y: number;
|
|
|
|
form_id: number;
|
|
|
|
}
|
|
|
|
|
2022-01-16 07:26:17 +00:00
|
|
|
type Props = {
|
|
|
|
selectedCell: [number, number] | null;
|
|
|
|
setSelectedCell: (cell: [number, number] | null) => void;
|
|
|
|
map: React.MutableRefObject<mapboxgl.Map | null>;
|
|
|
|
};
|
|
|
|
|
|
|
|
const Sidebar: React.FC<Props> = ({ selectedCell, setSelectedCell, map }) => {
|
|
|
|
const onClose = () => {
|
|
|
|
setSelectedCell(null);
|
2022-01-16 07:52:34 +00:00
|
|
|
if (map.current) map.current.removeFeatureState({ source: "grid-source" });
|
2022-01-17 21:47:24 +00:00
|
|
|
if (map.current && map.current.getLayer("selected-cell-layer")) {
|
|
|
|
map.current.removeLayer("selected-cell-layer");
|
|
|
|
}
|
|
|
|
if (map.current && map.current.getSource("selected-cell-source")) {
|
|
|
|
map.current.removeSource("selected-cell-source");
|
|
|
|
}
|
2022-01-19 06:06:19 +00:00
|
|
|
requestAnimationFrame(() => {
|
|
|
|
if (map.current) map.current.resize();
|
|
|
|
});
|
|
|
|
};
|
2022-01-16 07:26:17 +00:00
|
|
|
|
2022-01-19 06:06:19 +00:00
|
|
|
return (
|
|
|
|
selectedCell && (
|
|
|
|
<div className={styles.sidebar}>
|
|
|
|
<button className={styles.close} onClick={onClose}>
|
|
|
|
✖
|
|
|
|
</button>
|
|
|
|
<h1>
|
|
|
|
Cell {selectedCell[0]}, {selectedCell[1]}
|
|
|
|
</h1>
|
|
|
|
{selectedCell && <CellData selectedCell={selectedCell} />}
|
|
|
|
</div>
|
|
|
|
)
|
2022-01-16 07:26:17 +00:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2022-01-19 06:06:19 +00:00
|
|
|
export default Sidebar;
|