Last active
August 17, 2020 16:21
-
-
Save skflowne/dabd1841e302d848f1304bc7e919efa1 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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