From dc9c601f0ca20e86a94ec2c1864516e97fe68485 Mon Sep 17 00:00:00 2001
From: Alexandre Fauquette <45398769+alexfauquette@users.noreply.github.com>
Date: Fri, 13 Dec 2024 00:29:07 +0100
Subject: [PATCH] fix: make world an empty country code (#1100)
* make world an empty country code
* update country management
* fix console errors
* fix nav bar world display
* show off data by default
---
src/assets/countries.json | 2 +-
src/components/ResponsiveAppBar.jsx | 25 +++++++++--------
.../CountryProvider/CountryProvider.tsx | 15 +++++++---
src/pages/nutrition/NutrimentCell.tsx | 2 +-
src/pages/nutrition/index.tsx | 7 +++--
update-countries.js | 28 ++++++++++++-------
6 files changed, 49 insertions(+), 30 deletions(-)
diff --git a/src/assets/countries.json b/src/assets/countries.json
index 4987938ec..91e69b3d6 100644
--- a/src/assets/countries.json
+++ b/src/assets/countries.json
@@ -1485,7 +1485,7 @@
"id": "en:world",
"label": "World",
"languageCode": "en",
- "countryCode": "world"
+ "countryCode": ""
},
{
"id": "en:yemen",
diff --git a/src/components/ResponsiveAppBar.jsx b/src/components/ResponsiveAppBar.jsx
index d991f7385..07da99c1c 100644
--- a/src/components/ResponsiveAppBar.jsx
+++ b/src/components/ResponsiveAppBar.jsx
@@ -413,21 +413,22 @@ const ResponsiveAppBar = () => {
}}
>
c.countryCode));
export function CountryProvider({ children }) {
- const [country, setCountry] = useLocalStorageState("country", "world");
+ const [country, setCountry] = useLocalStorageState("country", "");
const [searchParams, setSearchParams] = useSearchParams();
const searchParamsCountry = searchParams.get("country")?.toLowerCase();
@@ -26,9 +26,16 @@ export function CountryProvider({ children }) {
);
const value = React.useMemo(() => {
- const lowercasedCountry = (
- ValidCountryCodes.has(searchParamsCountry) ? searchParamsCountry : country
- )?.toLocaleLowerCase();
+ // Try from:
+ // - searchParams
+ // - localStorage
+ // - empty
+
+ const lowercasedCountry = ValidCountryCodes.has(searchParamsCountry)
+ ? searchParamsCountry
+ : ValidCountryCodes.has(country?.toLocaleLowerCase())
+ ? country?.toLocaleLowerCase()
+ : "";
return {
country: lowercasedCountry,
diff --git a/src/pages/nutrition/NutrimentCell.tsx b/src/pages/nutrition/NutrimentCell.tsx
index 696a37261..06b26697b 100644
--- a/src/pages/nutrition/NutrimentCell.tsx
+++ b/src/pages/nutrition/NutrimentCell.tsx
@@ -74,7 +74,7 @@ export const NutrimentCell = (props: NutrimentCellProps) => {
{isValidUnit(unit) ? (