Skip to content

Commit b7fd186

Browse files
committed
bugfix: no selection reset on map overview clicks
1 parent 8a26978 commit b7fd186

File tree

3 files changed

+34
-17
lines changed

3 files changed

+34
-17
lines changed
Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,10 @@
11
import { FC, PropsWithChildren } from "react";
2-
import { useDispatch, useSelector } from "react-redux";
3-
4-
import { useActiveDataItem } from "@/hooks";
5-
import { deselectPaper } from "@/js/actions";
2+
import { useSelector } from "react-redux";
63

74
import { getMapHeight } from "./selectors";
85

96
export const HeightContainer: FC<PropsWithChildren> = ({ children }) => {
10-
const { selectedItemId } = useActiveDataItem();
117
const height = useSelector(getMapHeight);
12-
const dispatch = useDispatch();
13-
14-
const handleMapClick = () => {
15-
if (!selectedItemId) return;
16-
17-
dispatch(deselectPaper());
18-
};
198

20-
return (
21-
<div style={{ height }} onClick={handleMapClick}>
22-
{children}
23-
</div>
24-
);
9+
return <div style={{ height }}>{children}</div>;
2510
};
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { FC, useRef } from "react";
2+
import { useMapEvent } from "react-leaflet";
3+
import { useDispatch } from "react-redux";
4+
5+
import { useActiveDataItem } from "@/hooks";
6+
import { deselectPaper } from "@/js/actions";
7+
8+
export const SelectionResetHandler: FC = () => {
9+
const dispatch = useDispatch();
10+
const { selectedItemId } = useActiveDataItem();
11+
const isMovingRef = useRef(false);
12+
13+
useMapEvent("movestart", () => {
14+
isMovingRef.current = true;
15+
});
16+
17+
useMapEvent("moveend", () => {
18+
requestAnimationFrame(() => {
19+
isMovingRef.current = false;
20+
});
21+
});
22+
23+
useMapEvent("click", () => {
24+
if (!selectedItemId || isMovingRef.current) return;
25+
26+
dispatch(deselectPaper());
27+
});
28+
29+
return null;
30+
};

vis/js/templates/Geomap/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@ import { CONFIG } from "./config";
77
import { HeightContainer } from "./HeightContainer";
88
import { Layer } from "./Layer";
99
import { Pins } from "./Pins";
10+
import { SelectionResetHandler } from "./SelectionResetHandler";
1011
import { ZoomControls } from "./ZoomControls";
1112

1213
export const Geomap: FC = () => (
1314
<HeightContainer>
1415
<MapContainer {...CONFIG} className="geomap_container">
16+
<SelectionResetHandler />
1517
<ZoomControls />
1618
<Layer />
1719
<Pins />

0 commit comments

Comments
 (0)