Skip to content

Instantly share code, notes, and snippets.

@skflowne
Last active August 17, 2020 16:21
Show Gist options
  • Save skflowne/dabd1841e302d848f1304bc7e919efa1 to your computer and use it in GitHub Desktop.
Save skflowne/dabd1841e302d848f1304bc7e919efa1 to your computer and use it in GitHub Desktop.
import React from "react"
import { useRecoilValueLoadable, useRecoilValue } from "recoil"
import { mapboxToken } from "../../mapbox-token"
import { countriesQuery, currentDateStatusState } from "../../state/api"
import { currentStatState, currentStatMaxState } from "../../state/app"
import DataMap from "./DataMap"
import LoadingIndicator from "../ui/LoadingIndicator"
const TimelineMap = () => {
const dateStatus = useRecoilValueLoadable(currentDateStatusState)
const countries = useRecoilValueLoadable(countriesQuery)
const currentStat = useRecoilValue(currentStatState)
const currentStatMax = useRecoilValueLoadable(currentStatMaxState)
const isLoading =
dateStatus.state === "loading" || countries.state === "loading" || currentStatMax.state === "loading"
let data = []
if (!isLoading) {
data = dateStatus.contents.map((status) => {
const country = countries.contents[status.country]
return {
name: country.name,
coordinates: [country.longitude, country.latitude],
...status,
}
})
}
return (
<div className="timeline-map">
{isLoading ? <LoadingIndicator /> : null}
<DataMap
mapboxToken={mapboxToken}
data={data}
displayStat={currentStat}
statMax={currentStatMax.contents}
/>
</div>
)
}
export default TimelineMap
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment