@@ -12,7 +12,7 @@ import { useTheme } from "next-themes"
1212import { meetups } from "@/components/meetups"
1313
1414import { bootMeetupsMap , type MapHandle , type MarkerPoint } from "./map/engine"
15- import { MapTooltip , type MeetupMapPointer } from "./map/map-tooltip"
15+ import { MapTooltip } from "./map/map-tooltip"
1616import { MapSkeleton } from "./map-skeleton"
1717import { MeetupsList } from "./meetups-list"
1818import { asRgbString , MAP_COLORS , MapColors } from "./map/map-colors"
@@ -45,34 +45,33 @@ export function MeetupsMap() {
4545
4646 const [ status , setStatus ] = useState < MapStatus > ( "loading" )
4747 const [ errorMessage , setErrorMessage ] = useState < string | null > ( null )
48- const [ pointer , setPointer ] = useState < MeetupMapPointer > ( {
49- x : 0 ,
50- y : 0 ,
51- visible : false ,
52- } )
5348
5449 const handlePointerMove = ( event : ReactPointerEvent < HTMLDivElement > ) => {
50+ const tooltip = document . getElementById ( "map-tooltip" )
51+ if ( ! tooltip ) return
5552 const rect = event . currentTarget . getBoundingClientRect ( )
5653 const x = event . clientX - rect . left
5754 const y = event . clientY - rect . top
58- setPointer ( previous => {
59- if (
60- previous . visible &&
61- Math . abs ( previous . x - x ) < 0.5 &&
62- Math . abs ( previous . y - y ) < 0.5
63- ) {
64- return previous
65- }
66- return { x, y, visible : true }
67- } )
55+ tooltip . style . setProperty ( "--x" , `${ x } px` )
56+ tooltip . style . setProperty ( "--y" , `${ y } px` )
6857 }
6958
7059 const handlePointerLeave = ( ) => {
71- setPointer ( previous =>
72- previous . visible
73- ? { x : previous . x , y : previous . y , visible : false }
74- : previous ,
75- )
60+ const tooltip = document . getElementById ( "map-tooltip" )
61+ if ( ! tooltip ) return
62+ tooltip . style . removeProperty ( "--x" )
63+ tooltip . style . removeProperty ( "--y" )
64+ }
65+
66+ const activeMeetup = useMemo (
67+ ( ) => meetups . find ( m => m . node . id === activeMeetupId ) ,
68+ [ activeMeetupId ] ,
69+ )
70+
71+ const handleMapClick = ( ) => {
72+ if ( activeMeetup ?. node . link ) {
73+ window . open ( activeMeetup . node . link , "_blank" , "noopener,noreferrer" )
74+ }
7675 }
7776
7877 useEffect ( ( ) => {
@@ -158,6 +157,8 @@ export function MeetupsMap() {
158157 className = "group/map relative grow border-neu-200 bg-[--sea] dark:border-neu-50 dark:bg-[--sea] md:border-l"
159158 onPointerMove = { handlePointerMove }
160159 onPointerLeave = { handlePointerLeave }
160+ onClick = { handleMapClick }
161+ style = { { cursor : activeMeetup ? "pointer" : "default" } }
161162 >
162163 < canvas
163164 ref = { canvasRef }
@@ -171,11 +172,7 @@ export function MeetupsMap() {
171172 } }
172173 />
173174
174- < MapTooltip
175- id = "map-tooltip"
176- activeMeetupId = { activeMeetupId }
177- pointer = { pointer }
178- />
175+ < MapTooltip id = "map-tooltip" activeMeetupId = { activeMeetupId } />
179176
180177 < InfoTip />
181178
0 commit comments