From 2c1c7b581e1eaa2ccca08f4935f89068ccd9aaf7 Mon Sep 17 00:00:00 2001 From: Filip Czaplicki Date: Mon, 7 Aug 2023 23:22:27 +0200 Subject: [PATCH] Use data path from backend for World --- src/components/downloadCard.tsx | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/src/components/downloadCard.tsx b/src/components/downloadCard.tsx index 07d4b44..3b05c23 100644 --- a/src/components/downloadCard.tsx +++ b/src/components/downloadCard.tsx @@ -13,14 +13,6 @@ export default function DownloadCard() { result = result.toUpperCase(); return result; } - function worldAsCountry(count: number): Country { - return { - code: "", - names: { default: t("sidebar.world"), [resolvedLanguageToBackendLanguage()]: t("sidebar.world") }, - featureCount: count, - dataPath: "/data/world.geojson", - }; - } function countryName(country: Country) { const backendLanguage = resolvedLanguageToBackendLanguage(); if (Object.hasOwn(country.names, backendLanguage)) { @@ -29,14 +21,14 @@ export default function DownloadCard() { return country.names.default; } const [countries, setCountries] = useState>([]); - const world = worldAsCountry(countries.reduce((acc, country) => acc + country.featureCount, 0)); const sortedCountriesByName = countries .sort((a: Country, b: Country) => { if (a.code === "WORLD") return -1; if (b.code === "WORLD") return 1; return countryName(a) < countryName(b) ? -1 : 1; }); - const [selectedCountry, setSelectedCountry] = useState(world); + const [selectedCountryCode, setSelectedCountryCode] = useState("WORLD"); + const selectedCountry = countries.find((country) => country.code === selectedCountryCode); useEffect(() => { const fetchData = async () => { const data = await fetchCountriesData(); @@ -60,7 +52,7 @@ export default function DownloadCard() { onChange={(e) => { const selected = sortedCountriesByName .find((country) => country.code === e.target.value); - if (selected !== undefined) setSelectedCountry(selected); + if (selected !== undefined) setSelectedCountryCode(selected.code); }} > { sortedCountriesByName.map((country) => ( @@ -69,7 +61,7 @@ export default function DownloadCard() {