Skip to content

Commit

Permalink
Allow to limit country names by language
Browse files Browse the repository at this point in the history
  • Loading branch information
starsep committed Nov 16, 2023
1 parent 9abe63a commit 1441d87
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/backend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ interface BackendCountry {
data_path: string;
}

export async function fetchCountriesData(): Promise<Array<Country> | null> {
const url = `${backendBaseUrl}/api/v1/countries/names`;
export async function fetchCountriesData(language: string): Promise<Array<Country> | null> {
const url = `${backendBaseUrl}/api/v1/countries/names?language=${language.toUpperCase()}`;
return fetch(url)
.then((response) => response.json())
.then((response: Array<BackendCountry>) => response.map((country: BackendCountry) => ({
Expand Down
4 changes: 2 additions & 2 deletions src/components/downloadCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ export default function DownloadCard() {
const selectedCountry = countries.find((country) => country.code === selectedCountryCode);
useEffect(() => {
const fetchData = async () => {
const data = await fetchCountriesData();
const data = await fetchCountriesData(language);
if (data !== null) setCountries(data);
};
fetchData().catch(console.error);
}, []);
}, [language]);

function countryLabel(country: Country) {
return `${countryName(country)} (${country.featureCount})`;
Expand Down

0 comments on commit 1441d87

Please sign in to comment.