Fix mod selection and deselection
This commit is contained in:
@@ -147,7 +147,6 @@ const Map: React.FC = () => {
|
||||
|
||||
const clearSelectedCell = useCallback(() => {
|
||||
setSelectedCell(null);
|
||||
router.push({ query: {} });
|
||||
if (map.current) map.current.removeFeatureState({ source: "grid-source" });
|
||||
if (map.current && map.current.getLayer("selected-cell-layer")) {
|
||||
map.current.removeLayer("selected-cell-layer");
|
||||
@@ -158,7 +157,13 @@ const Map: React.FC = () => {
|
||||
requestAnimationFrame(() => {
|
||||
if (map.current) map.current.resize();
|
||||
});
|
||||
}, [map, router]);
|
||||
}, [map]);
|
||||
|
||||
const clearSelectedMod = useCallback(() => {
|
||||
requestAnimationFrame(() => {
|
||||
if (map.current) map.current.resize();
|
||||
});
|
||||
}, [map]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!heatmapLoaded) return; // wait for all map layers to load
|
||||
@@ -183,11 +188,19 @@ const Map: React.FC = () => {
|
||||
}, [
|
||||
selectedCell,
|
||||
router.query.cell,
|
||||
router.query.mod,
|
||||
selectCell,
|
||||
clearSelectedCell,
|
||||
heatmapLoaded,
|
||||
]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!heatmapLoaded) return; // wait for all map layers to load
|
||||
if (!router.query.mod || typeof router.query.mod !== "string") {
|
||||
clearSelectedMod();
|
||||
}
|
||||
}, [router.query.mod, clearSelectedMod, heatmapLoaded]);
|
||||
|
||||
useEffect(() => {
|
||||
if (map.current) return; // initialize map only once
|
||||
map.current = new mapboxgl.Map({
|
||||
|
||||
@@ -76,7 +76,7 @@ const ModData: React.FC<Props> = ({ selectedMod, counts }) => {
|
||||
<h1>
|
||||
<a
|
||||
href={`${NEXUS_MODS_URL}/mods/${data.nexus_mod_id}`}
|
||||
className={styles.link}
|
||||
className={`${styles.link} ${styles.name}`}
|
||||
>
|
||||
{data.name}
|
||||
</a>
|
||||
|
||||
@@ -91,7 +91,6 @@ const SearchBar: React.FC<Props> = ({ clearSelectedCell, map }) => {
|
||||
const onChooseResult =
|
||||
(item: Mod) =>
|
||||
(e: React.MouseEvent<HTMLElement> | React.TouchEvent<HTMLElement>) => {
|
||||
clearSelectedCell();
|
||||
router.push({ query: { mod: item.id } });
|
||||
setSearch("");
|
||||
setResults([]);
|
||||
|
||||
Reference in New Issue
Block a user