-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add country selection to preferences and use it to query the API acco…
…rdingly
- Loading branch information
Showing
7 changed files
with
41 additions
and
14 deletions.
There are no files selected for viewing
This file contains 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,19 @@ | ||
import { getTaxo, type Language } from '$lib/api'; | ||
import { getTaxo } from '$lib/api'; | ||
import type { Country, Language } from 'openfoodfacts-nodejs'; | ||
import type { PageLoad } from './$types'; | ||
|
||
export const load = (async ({ fetch }) => { | ||
const languages = await getTaxo<Language>('languages', fetch); | ||
let countries = await getTaxo<Country>('countries', fetch); | ||
|
||
// FIX: not every country has a language_code_2, so we need to filter them out | ||
// as they are used to store the language preference and to query the API | ||
countries = Object.fromEntries( | ||
Object.entries(countries).filter(([, country]) => country.country_code_2 != null) | ||
); | ||
|
||
return { | ||
languages | ||
languages, | ||
countries | ||
}; | ||
}) satisfies PageLoad; |