Created
August 15, 2020 15:48
-
-
Save skflowne/b8e1db6dedf98715564aad26fcc40c65 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 } from "recoil" | |
import { mapboxToken } from "../../mapbox-token" | |
import { countriesQuery, currentDateStatusState } from "../../state/api" | |
import DataMap from "./DataMap" | |
import LoadingIndicator from "../ui/LoadingIndicator" | |
const TimelineMap = () => { | |
const dateStatus = useRecoilValueLoadable(currentDateStatusState) | |
const countries = useRecoilValueLoadable(countriesQuery) | |
const isLoading = dateStatus.state === "loading" || countries.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} /> | |
</div> | |
) | |
} | |
export default TimelineMap |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment