Fix mod selection and deselection

This commit is contained in:
Tyler Hallada 2022-01-30 16:14:32 -05:00
parent 716900a397
commit 8bae1c03c8
5 changed files with 25 additions and 5 deletions

View File

@ -147,7 +147,6 @@ const Map: React.FC = () => {
const clearSelectedCell = useCallback(() => { const clearSelectedCell = useCallback(() => {
setSelectedCell(null); setSelectedCell(null);
router.push({ query: {} });
if (map.current) map.current.removeFeatureState({ source: "grid-source" }); if (map.current) map.current.removeFeatureState({ source: "grid-source" });
if (map.current && map.current.getLayer("selected-cell-layer")) { if (map.current && map.current.getLayer("selected-cell-layer")) {
map.current.removeLayer("selected-cell-layer"); map.current.removeLayer("selected-cell-layer");
@ -158,7 +157,13 @@ const Map: React.FC = () => {
requestAnimationFrame(() => { requestAnimationFrame(() => {
if (map.current) map.current.resize(); if (map.current) map.current.resize();
}); });
}, [map, router]); }, [map]);
const clearSelectedMod = useCallback(() => {
requestAnimationFrame(() => {
if (map.current) map.current.resize();
});
}, [map]);
useEffect(() => { useEffect(() => {
if (!heatmapLoaded) return; // wait for all map layers to load if (!heatmapLoaded) return; // wait for all map layers to load
@ -183,11 +188,19 @@ const Map: React.FC = () => {
}, [ }, [
selectedCell, selectedCell,
router.query.cell, router.query.cell,
router.query.mod,
selectCell, selectCell,
clearSelectedCell, clearSelectedCell,
heatmapLoaded, 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(() => { useEffect(() => {
if (map.current) return; // initialize map only once if (map.current) return; // initialize map only once
map.current = new mapboxgl.Map({ map.current = new mapboxgl.Map({

View File

@ -76,7 +76,7 @@ const ModData: React.FC<Props> = ({ selectedMod, counts }) => {
<h1> <h1>
<a <a
href={`${NEXUS_MODS_URL}/mods/${data.nexus_mod_id}`} href={`${NEXUS_MODS_URL}/mods/${data.nexus_mod_id}`}
className={styles.link} className={`${styles.link} ${styles.name}`}
> >
{data.name} {data.name}
</a> </a>

View File

@ -91,7 +91,6 @@ const SearchBar: React.FC<Props> = ({ clearSelectedCell, map }) => {
const onChooseResult = const onChooseResult =
(item: Mod) => (item: Mod) =>
(e: React.MouseEvent<HTMLElement> | React.TouchEvent<HTMLElement>) => { (e: React.MouseEvent<HTMLElement> | React.TouchEvent<HTMLElement>) => {
clearSelectedCell();
router.push({ query: { mod: item.id } }); router.push({ query: { mod: item.id } });
setSearch(""); setSearch("");
setResults([]); setResults([]);

View File

@ -1,3 +1,11 @@
.status { .status {
margin-top: 24px; margin-top: 24px;
} }
a.link {
color: #72030a;
}
a.name {
line-height: 1.75rem;
}

View File

@ -28,7 +28,7 @@
.close { .close {
position: fixed; position: fixed;
top: 8px; top: 8px;
left: 232px; left: 240px;
font-size: 24px; font-size: 24px;
margin-left: 12px; margin-left: 12px;
border: none; border: none;