File tree Expand file tree Collapse file tree 3 files changed +34
-17
lines changed
Expand file tree Collapse file tree 3 files changed +34
-17
lines changed Original file line number Diff line number Diff line change 11import { 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
74import { getMapHeight } from "./selectors" ;
85
96export 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} ;
Original file line number Diff line number Diff line change 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+ } ;
Original file line number Diff line number Diff line change @@ -7,11 +7,13 @@ import { CONFIG } from "./config";
77import { HeightContainer } from "./HeightContainer" ;
88import { Layer } from "./Layer" ;
99import { Pins } from "./Pins" ;
10+ import { SelectionResetHandler } from "./SelectionResetHandler" ;
1011import { ZoomControls } from "./ZoomControls" ;
1112
1213export const Geomap : FC = ( ) => (
1314 < HeightContainer >
1415 < MapContainer { ...CONFIG } className = "geomap_container" >
16+ < SelectionResetHandler />
1517 < ZoomControls />
1618 < Layer />
1719 < Pins />
You can’t perform that action at this time.
0 commit comments