-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
95 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.kiosk-latest-activities__map { | ||
flex: 1; | ||
overflow: hidden; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
35 changes: 35 additions & 0 deletions
35
src/client/pages/Kiosk/LatestActivities/Map/hooks/useLatestActivitiesMap.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from './Map' |
8 changes: 8 additions & 0 deletions
8
src/client/pages/Kiosk/LatestActivities/MapWrapper/MapWrapper.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
31
src/client/pages/Kiosk/LatestActivities/MapWrapper/MapWrapper.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from './MapWrapper' |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.