From d76bf32c9dcc83ebd0bae979726b1456a9028d8b Mon Sep 17 00:00:00 2001 From: TheCatLady <52870424+TheCatLady@users.noreply.github.com> Date: Tue, 16 Mar 2021 12:13:52 -0400 Subject: [PATCH] fix(ui): sort regions & languages by their localized names rather than their TMDb English names (#1157) --- src/components/RegionSelector/index.tsx | 25 ++++++++++++++++++- src/components/Settings/SettingsMain.tsx | 23 +++++++++++++++-- .../UserGeneralSettings/index.tsx | 23 +++++++++++++++-- 3 files changed, 66 insertions(+), 5 deletions(-) diff --git a/src/components/RegionSelector/index.tsx b/src/components/RegionSelector/index.tsx index 4537d5547..2cbdc4351 100644 --- a/src/components/RegionSelector/index.tsx +++ b/src/components/RegionSelector/index.tsx @@ -38,6 +38,29 @@ const RegionSelector: React.FC = ({ [] ); + const sortedRegions = useMemo( + () => + regions?.sort((region1, region2) => { + const region1Name = + intl.formatDisplayName(region1.iso_3166_1, { + type: 'region', + fallback: 'none', + }) ?? region1.english_name; + const region2Name = + intl.formatDisplayName(region2.iso_3166_1, { + type: 'region', + fallback: 'none', + }) ?? region2.english_name; + + return region1Name === region2Name + ? 0 + : region1Name > region2Name + ? 1 + : -1; + }), + [intl, regions] + ); + const defaultRegionNameFallback = regions?.find((region) => region.iso_3166_1 === currentSettings.region) ?.english_name ?? currentSettings.region; @@ -228,7 +251,7 @@ const RegionSelector: React.FC = ({ )} - {regions?.map((region) => ( + {sortedRegions?.map((region) => ( {({ selected, active }) => (
{ } }; + const sortedLanguages = useMemo( + () => + languages?.sort((lang1, lang2) => { + const lang1Name = + intl.formatDisplayName(lang1.iso_639_1, { + type: 'language', + fallback: 'none', + }) ?? lang1.english_name; + const lang2Name = + intl.formatDisplayName(lang2.iso_639_1, { + type: 'language', + fallback: 'none', + }) ?? lang2.english_name; + + return lang1Name === lang2Name ? 0 : lang1Name > lang2Name ? 1 : -1; + }), + [intl, languages] + ); + if (!data && !error && !languages && !languagesError) { return ; } @@ -306,7 +325,7 @@ const SettingsMain: React.FC = () => { - {languages?.map((language) => ( + {sortedLanguages?.map((language) => (