Skip to content

Commit

Permalink
4204 - Add base map
Browse files Browse the repository at this point in the history
  • Loading branch information
yaguzmang committed Jan 23, 2025
1 parent 2248738 commit 6968e43
Show file tree
Hide file tree
Showing 9 changed files with 95 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/client/pages/Kiosk/LatestActivities/LatestActivities.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import React from 'react'

import MapWrapper from 'client/pages/Kiosk/LatestActivities/MapWrapper'

const LatestActivities: React.FC = () => {
return <div />
return <MapWrapper />
}

export default LatestActivities
4 changes: 4 additions & 0 deletions src/client/pages/Kiosk/LatestActivities/Map/Map.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.kiosk-latest-activities__map {
flex: 1;
overflow: hidden;
}
12 changes: 12 additions & 0 deletions src/client/pages/Kiosk/LatestActivities/Map/Map.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import './Map.scss'
import React from 'react'

import { useLatestActivitiesMap } from './hooks/useLatestActivitiesMap'

const Map: React.FC = () => {
const { ref } = useLatestActivitiesMap()

return <div ref={ref} className="kiosk-latest-activities__map" />
}

export default Map
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { MutableRefObject, useEffect, useRef, useState } from 'react'

type Returned = {
map: google.maps.Map
ref: MutableRefObject<HTMLDivElement>
}

const baseMapOptions = {
center: { lat: 0, lng: 0 },
disableDefaultUI: true,
fullscreenControl: false,
mapTypeControl: false,
mapTypeId: 'roadmap',
maxZoom: 15,
minZoom: 3,
rotateControl: false,
zoom: 3,
}

export const useLatestActivitiesMap = (): Returned => {
const ref = useRef<HTMLDivElement>(null)
const [map, setMap] = useState<google.maps.Map>()

useEffect(() => {
if (!ref.current || map) return

const mapSetup = new window.google.maps.Map(ref.current, baseMapOptions)

setMap(mapSetup)
}, [map, ref])

return { map, ref }
}

export default useLatestActivitiesMap
1 change: 1 addition & 0 deletions src/client/pages/Kiosk/LatestActivities/Map/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from './Map'
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
@import 'src/client/style/partials';

.kiosk-latest-activities__map-error {
align-self: center;
color: $ui-destructive;
font-size: $font-l;
margin: 0 auto;
}
31 changes: 31 additions & 0 deletions src/client/pages/Kiosk/LatestActivities/MapWrapper/MapWrapper.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import './MapWrapper.scss'
import React from 'react'

import { Status, Wrapper, WrapperProps } from '@googlemaps/react-wrapper'

import Loading from 'client/components/Loading'
import Map from 'client/pages/Kiosk/LatestActivities/Map'

// @ts-ignore
// from webpack DefinePlugin
const apiKey: string = __GOOGLE_MAPS_API_KEY__

const Components: Record<Status, React.FC> = {
[Status.LOADING]: () => <Loading />,
[Status.FAILURE]: () => (
<div className="kiosk-latest-activities__map-error">There was a problem while loading the map.</div>
),
[Status.SUCCESS]: () => <Map />,
}

const MapWrapper: React.FC = () => {
const render: WrapperProps['render'] = (status) => {
const Component = Components[status]

return <Component />
}

return <Wrapper apiKey={apiKey} render={render} />
}

export default MapWrapper
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from './MapWrapper'
Binary file added web-resources/img/kiosk/latest-activities.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 6968e43

Please sign in to comment.