Fix rendering fetchedPlugin cells on initial load

This commit is contained in:
Tyler Hallada 2022-03-14 21:59:03 -04:00
parent a590dbd02c
commit 824202d3a6

View File

@ -4,8 +4,8 @@ import Gradient from "javascript-color-gradient";
import mapboxgl from "mapbox-gl"; import mapboxgl from "mapbox-gl";
import useSWRImmutable from "swr/immutable"; import useSWRImmutable from "swr/immutable";
import { useAppDispatch, useAppSelector } from "../lib/hooks"; import { useAppSelector } from "../lib/hooks";
import { PluginFile, setFetchedPlugin } from "../slices/plugins"; import { PluginFile } from "../slices/plugins";
import styles from "../styles/Map.module.css"; import styles from "../styles/Map.module.css";
import Sidebar from "./Sidebar"; import Sidebar from "./Sidebar";
import ToggleLayersControl from "./ToggleLayersControl"; import ToggleLayersControl from "./ToggleLayersControl";
@ -59,7 +59,6 @@ const Map: React.FC = () => {
| null | null
>(null); >(null);
const [sidebarOpen, setSidebarOpen] = useState(true); const [sidebarOpen, setSidebarOpen] = useState(true);
const dispatch = useAppDispatch();
const plugins = useAppSelector((state) => state.plugins.plugins); const plugins = useAppSelector((state) => state.plugins.plugins);
const pluginsPending = useAppSelector((state) => state.plugins.pending); const pluginsPending = useAppSelector((state) => state.plugins.pending);
@ -362,6 +361,7 @@ const Map: React.FC = () => {
]); ]);
useEffect(() => { useEffect(() => {
if (!heatmapLoaded) return; // wait for all map layers to load
if ( if (
router.query.plugin && router.query.plugin &&
typeof router.query.plugin === "string" && typeof router.query.plugin === "string" &&
@ -382,7 +382,7 @@ const Map: React.FC = () => {
} }
selectCells(cells); selectCells(cells);
} }
}, [fetchedPlugin, selectCells, router.query.plugin]); }, [heatmapLoaded, fetchedPlugin, selectCells, router.query.plugin]);
useEffect(() => { useEffect(() => {
if (!heatmapLoaded) return; // wait for all map layers to load if (!heatmapLoaded) return; // wait for all map layers to load