Skip to content

Commit

Permalink
chore: view port for mobile devices
Browse files Browse the repository at this point in the history
  • Loading branch information
siddhart1o1 committed Feb 10, 2024
1 parent 5b074dd commit 241383c
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions apps/map/components/map/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export default function MapComponent({ mapData, googleMapsApiKey }: MapComponent
const [selectedMarker, setSelectedMarker] = useState<
BusinessMapMarkersQuery["businessMapMarkers"][number] | null
>(null)
const [viewportHeight, setViewportHeight] = useState("100vh")
const [currentLocation, setCurrentLocation] = useState({
coordinates: {
lat: DEFAULT_LAT,
Expand All @@ -27,6 +28,15 @@ export default function MapComponent({ mapData, googleMapsApiKey }: MapComponent
userAllowedLocation: false,
})

useEffect(() => {
const calculateViewportHeight = () => {
setViewportHeight(`${window.innerHeight}px`)
}
calculateViewportHeight()
window.addEventListener("resize", calculateViewportHeight)
return () => window.removeEventListener("resize", calculateViewportHeight)
}, [])

const [draggablePin, setDraggablePin] = useState({
coordinates: { lat: 0, lng: 0 },
visible: false,
Expand Down Expand Up @@ -159,7 +169,14 @@ export default function MapComponent({ mapData, googleMapsApiKey }: MapComponent
}

return (
<>
<div
style={{
position: "relative",
height: viewportHeight,
width: "100vw",
overflow: "hidden",
}}
>
{draggablePin.visible && (
<div className="absolute right-2 top-2 z-10 w-40">
<div className="bg-white text-black p-2 rounded-md text-sm drop-shadow-2xl">
Expand Down Expand Up @@ -229,7 +246,7 @@ export default function MapComponent({ mapData, googleMapsApiKey }: MapComponent
zoom={14}
center={currentLocation.coordinates}
mapTypeId={google.maps.MapTypeId.ROADMAP}
mapContainerStyle={{ width: "100vw", height: "100vh" }}
mapContainerStyle={{ height: "100%", width: "100%" }}
>
{mapData.map((marker, index) => (
<MarkerF
Expand Down Expand Up @@ -296,7 +313,7 @@ export default function MapComponent({ mapData, googleMapsApiKey }: MapComponent
/>
)}
</GoogleMap>
</>
</div>
)
}

Expand Down

0 comments on commit 241383c

Please sign in to comment.