|
1 | 1 | "use client"; |
2 | | -import useRoom from "hooks/useRoom"; |
3 | | -import Image from "next/image"; |
4 | | -import { useEffect } from "react"; |
| 2 | + |
| 3 | +import React, { useEffect, useRef } from "react"; |
5 | 4 | import { Marker } from "react-map-gl/mapbox"; |
| 5 | +import { alpha } from "@mui/material"; |
| 6 | +import { Typography } from "@mui/material"; |
| 7 | +import Box from "@mui/material/Box"; |
| 8 | +import { useTheme } from "@mui/material/styles"; |
| 9 | +import useRoom from "hooks/useRoom"; |
6 | 10 |
|
7 | | -const RoomMapMarker = ({ |
8 | | - roomId, |
9 | | - roomLocation, |
10 | | -}: { |
| 11 | +interface RoomMapMarkerProps { |
11 | 12 | roomId: string; |
12 | 13 | roomLocation?: (lat: number, long: number) => void; |
| 14 | +} |
| 15 | + |
| 16 | +const RoomMapMarker: React.FC<RoomMapMarkerProps> = ({ |
| 17 | + roomId, |
| 18 | + roomLocation, |
13 | 19 | }) => { |
14 | 20 | const { room } = useRoom(roomId); |
| 21 | + const hasFocusedRef = useRef(false); |
| 22 | + const theme = useTheme(); |
15 | 23 |
|
16 | 24 | useEffect(() => { |
17 | | - if (room && roomLocation) { |
| 25 | + if (!hasFocusedRef.current && room && roomLocation) { |
18 | 26 | roomLocation(room.lat, room.long); |
| 27 | + hasFocusedRef.current = true; |
19 | 28 | } |
20 | 29 | }, [room, roomLocation]); |
21 | 30 |
|
22 | 31 | if (!room) return null; |
| 32 | + const blue = "#1976d2"; |
23 | 33 |
|
24 | 34 | return ( |
25 | | - <Marker |
26 | | - key={roomId} |
27 | | - latitude={room.lat} |
28 | | - longitude={room.long} |
29 | | - anchor="bottom" |
30 | | - > |
31 | | - <Image src="/MapPin.png" alt="Room pin" width={30} height={30} /> |
| 35 | + <Marker latitude={room.lat} longitude={room.long} anchor="bottom"> |
| 36 | + <div |
| 37 | + style={{ |
| 38 | + display: "flex", |
| 39 | + flexDirection: "column", |
| 40 | + alignItems: "center", |
| 41 | + position: "relative", |
| 42 | + }} |
| 43 | + > |
| 44 | + <Typography |
| 45 | + sx={{ |
| 46 | + fontSize: 11, |
| 47 | + fontWeight: 500, |
| 48 | + textShadow: |
| 49 | + theme.palette.mode === "light" |
| 50 | + ? "-.5px -.5px 1px #f2f2f2, .5px -.5px 1px #f2f2f2, -.5px .5px 1px #f2f2f2, .5px .5px 1px #f2f2f2" |
| 51 | + : "", |
| 52 | + color: theme.palette.text.primary, |
| 53 | + marginBottom: 1, |
| 54 | + userSelect: "none", |
| 55 | + }} |
| 56 | + > |
| 57 | + {room.name} |
| 58 | + </Typography> |
| 59 | + |
| 60 | + <Box |
| 61 | + sx={(theme) => ({ |
| 62 | + width: 18, |
| 63 | + height: 18, |
| 64 | + borderRadius: "50%", |
| 65 | + border: `5px solid ${blue}`, |
| 66 | + backgroundColor: "white", |
| 67 | + boxShadow: `0px 0px 6px 4px ${alpha(blue, 0.5)}`, |
| 68 | + position: "relative", |
| 69 | + "&:hover": { |
| 70 | + cursor: "pointer", |
| 71 | + }, |
| 72 | + })} |
| 73 | + /> |
| 74 | + </div> |
32 | 75 | </Marker> |
33 | 76 | ); |
34 | 77 | }; |
|
0 commit comments