diff --git a/src/localeStorageManager.ts b/src/localeStorageManager.ts index 61ceda0e1..7108e1fe2 100644 --- a/src/localeStorageManager.ts +++ b/src/localeStorageManager.ts @@ -16,6 +16,7 @@ const STORAGE_KEY = "hunger-game-settings"; export const localSettingsKeys = { language: "lang", + country: "country", colorMode: "colorMode", isDevMode: "devMode", visiblePages: "visiblePages", diff --git a/src/pages/eco-score/index.tsx b/src/pages/eco-score/index.tsx index 0c2853dff..dbb7f62e3 100644 --- a/src/pages/eco-score/index.tsx +++ b/src/pages/eco-score/index.tsx @@ -11,9 +11,10 @@ import SmallQuestionCard from "../../components/SmallQuestionCard"; import Opportunities from "../../components/Opportunities"; import { DEFAULT_FILTER_STATE } from "../../components/QuestionFilter/const"; import { useTranslation } from "react-i18next"; -import { capitaliseName } from "../../utils"; import Loader from "../loader"; import { useSearchParams } from "react-router-dom"; +import { localSettings } from "../../localeStorageManager"; +import countryNames from "../../assets/countries.json"; const ecoScoreCards = [ { @@ -148,33 +149,19 @@ const ecoScoreCards = [ }, ]; -export const countryNames = [ - "en:belgium", - "en:denmark", - "en:france", - "en:germany", - "en:italy", - "en:netherlands", - "en:portugal", - "en:spain", - "en:sweden", - "en:switzerland", - "en:united-states", - "en:canada", - "en:australia", - "en:united-kingdom", -]; + export default function EcoScore() { const { t } = useTranslation(); + const localData= localSettings.fetch(); const [searchParams, setSearchParams] = useSearchParams(); const [selectedCountry, setSelectedCountry] = React.useState( - searchParams.get("cc") || countryNames[0], + searchParams.get("cc") || localData['country'] || "en:france", ); React.useEffect(() => { setSearchParams({ cc: selectedCountry }); - }, [selectedCountry]); + }, [selectedCountry, searchParams]); return ( }> @@ -210,8 +197,8 @@ export default function EcoScore() { sx={{ width: 200 }} > {countryNames.map((country) => ( - - {capitaliseName(country)} + + {country.label} ))} diff --git a/src/pages/settings/index.jsx b/src/pages/settings/index.jsx index 0da58eabb..d4ea38580 100644 --- a/src/pages/settings/index.jsx +++ b/src/pages/settings/index.jsx @@ -22,15 +22,16 @@ import DevModeContext from "../../contexts/devMode"; import ColorModeContext from "../../contexts/colorMode"; import { localSettings, localSettingsKeys } from "../../localeStorageManager"; import FooterWithLinks from "../../components/Footer"; +import countryNames from "../../assets/countries.json"; export default function Settings() { const { t, i18n } = useTranslation(); const theme = useTheme(); const colorMode = React.useContext(ColorModeContext); - const [language, setLanguage] = React.useState(i18n.language); const { devMode, setDevMode, visiblePages, setVisiblePages } = React.useContext(DevModeContext); + const [selectedCountry, setSelectedCountry]= React.useState(() => localSettings.fetch()['country']) const handleDevModeChange = (event) => { localSettings.update(localSettingsKeys.isDevMode, event.target.checked); @@ -52,6 +53,11 @@ export default function Settings() { setLanguage(e.target.value); }; + const handleCountryChange= (e)=>{ + setSelectedCountry(e.target.value); + localSettings.update(localSettingsKeys.country, e.target.value) + } + return ( }> @@ -71,6 +77,19 @@ export default function Settings() { ))} + + {countryNames.map((country) => ( + + {country.label} + + ))} +

{t("settings.dev_mode_title")}