Created
August 15, 2020 16:12
-
-
Save skflowne/d18135d5f8955632b0dac90d84050a55 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 DataMap from "./DataMap" | |
import LoadingIndicator from "../ui/LoadingIndicator" | |
import { currentStatState } from "../../state/app" | |
const TimelineMap = () => { | |
const dateStatus = useRecoilValueLoadable(currentDateStatusState) | |
const countries = useRecoilValueLoadable(countriesQuery) | |
const currentStat = useRecoilValue(currentStatState) | |
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} displayStat={currentStat} /> | |
</div> | |
) | |
} | |
export default TimelineMap |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment