Fix clearing map selected cells between pages
Also limits fitBounds zooming to selecting mods or plugins only.
This commit is contained in:
parent
68796f6f9c
commit
daa4d3c039
@ -138,7 +138,7 @@ const Map: React.FC = () => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
const selectCells = useCallback(
|
const selectCells = useCallback(
|
||||||
(cells: { x: number; y: number }[]) => {
|
(cells: { x: number; y: number }[], { fitCells } = { fitCells: false }) => {
|
||||||
if (!map.current) return;
|
if (!map.current) return;
|
||||||
if (map.current && !map.current.getSource("grid-source")) return;
|
if (map.current && !map.current.getSource("grid-source")) return;
|
||||||
|
|
||||||
@ -168,6 +168,7 @@ const Map: React.FC = () => {
|
|||||||
visited[id] = true;
|
visited[id] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (fitCells) {
|
||||||
let bounds: mapboxgl.LngLatBounds | null = null;
|
let bounds: mapboxgl.LngLatBounds | null = null;
|
||||||
const fitBounds = () => {
|
const fitBounds = () => {
|
||||||
const zoom = map.current.getZoom();
|
const zoom = map.current.getZoom();
|
||||||
@ -213,6 +214,7 @@ const Map: React.FC = () => {
|
|||||||
} else {
|
} else {
|
||||||
fitBounds();
|
fitBounds();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
[map]
|
[map]
|
||||||
);
|
);
|
||||||
@ -280,14 +282,14 @@ const Map: React.FC = () => {
|
|||||||
selectedCell.x !== cell.x ||
|
selectedCell.x !== cell.x ||
|
||||||
selectedCell.y !== cell.y
|
selectedCell.y !== cell.y
|
||||||
) {
|
) {
|
||||||
// clearSelectedCells();
|
clearSelectedCells();
|
||||||
selectCell(cell);
|
selectCell(cell);
|
||||||
}
|
}
|
||||||
} else if (router.query.mod && typeof router.query.mod === "string") {
|
} else if (router.query.mod && typeof router.query.mod === "string") {
|
||||||
if (selectedCells) {
|
if (selectedCells) {
|
||||||
clearSelectedCell();
|
clearSelectedCell();
|
||||||
setSidebarOpen(true);
|
setSidebarOpen(true);
|
||||||
selectCells(selectedCells);
|
selectCells(selectedCells, { fitCells: true });
|
||||||
} else {
|
} else {
|
||||||
// TODO: this is so spaghetti
|
// TODO: this is so spaghetti
|
||||||
clearSelectedCell();
|
clearSelectedCell();
|
||||||
@ -311,12 +313,21 @@ const Map: React.FC = () => {
|
|||||||
cellSet.add(cell.x + cell.y * 1000);
|
cellSet.add(cell.x + cell.y * 1000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
selectCells(cells);
|
selectCells(cells, { fitCells: true });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (plugins && plugins.length > 0 && pluginsPending === 0) {
|
} else {
|
||||||
clearSelectedCells();
|
clearSelectedCells();
|
||||||
clearSelectedCell();
|
clearSelectedCell();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
plugins &&
|
||||||
|
plugins.length > 0 &&
|
||||||
|
pluginsPending === 0 &&
|
||||||
|
!router.query.mod &&
|
||||||
|
!router.query.plugin
|
||||||
|
) {
|
||||||
const cells = plugins.reduce(
|
const cells = plugins.reduce(
|
||||||
(acc: { x: number; y: number }[], plugin: PluginFile) => {
|
(acc: { x: number; y: number }[], plugin: PluginFile) => {
|
||||||
if (plugin.enabled && plugin.parsed) {
|
if (plugin.enabled && plugin.parsed) {
|
||||||
@ -337,9 +348,6 @@ const Map: React.FC = () => {
|
|||||||
[]
|
[]
|
||||||
);
|
);
|
||||||
selectCells(cells);
|
selectCells(cells);
|
||||||
} else {
|
|
||||||
clearSelectedCells();
|
|
||||||
clearSelectedCell();
|
|
||||||
}
|
}
|
||||||
}, [
|
}, [
|
||||||
selectedCell,
|
selectedCell,
|
||||||
|
Loading…
Reference in New Issue
Block a user