From aeba7be478995b14e118d787839d59ca06c0754d Mon Sep 17 00:00:00 2001 From: nevainero Date: Thu, 31 Mar 2022 12:45:48 +0300 Subject: [PATCH] fix(ott-2353): fix languages order --- src/config/clients/index.tsx | 2 +- src/config/clients/instat.tsx | 1 + src/config/languages.tsx | 12 +++++++++++- src/helpers/getSortedLangs/index.tsx | 18 ++++++++++++++++++ 4 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 src/helpers/getSortedLangs/index.tsx diff --git a/src/config/clients/index.tsx b/src/config/clients/index.tsx index b9eaa9da..e74608b5 100644 --- a/src/config/clients/index.tsx +++ b/src/config/clients/index.tsx @@ -3,7 +3,7 @@ import type { ClientConfig } from './types' import { facr } from './facr' import { instat } from './instat' -const currentClient = process.env.REACT_APP_CLIENT || 'instat' +export const currentClient = process.env.REACT_APP_CLIENT || 'instat' const clients = { facr, diff --git a/src/config/clients/instat.tsx b/src/config/clients/instat.tsx index b3dea450..ff981eb2 100644 --- a/src/config/clients/instat.tsx +++ b/src/config/clients/instat.tsx @@ -8,6 +8,7 @@ export const instat: ClientConfig = { auth: { clientId: ClientIds.Instat, }, + defaultLanguage: 'en', description: 'Live sports streaming platform. Football, basketball, ice hockey and more. Access to various player playlists and game highlights. Multiple subscription options. Available across all devices.', disabledPreferences: true, name: ClientNames.Instat, diff --git a/src/config/languages.tsx b/src/config/languages.tsx index 6bf78545..e6d752f0 100644 --- a/src/config/languages.tsx +++ b/src/config/languages.tsx @@ -1,4 +1,7 @@ -export const langsList = [ +import { currentClient } from 'config/clients' +import { getSortedLangs } from 'helpers/getSortedLangs' + +export const langs = [ { className: 'ru', locale: 'ru', @@ -66,4 +69,11 @@ export const langsList = [ }, ] as const +export const langsOrder = currentClient === 'instat' + ? ['en', 'bg', 'cs', 'fr', 'de', 'nl', 'it', 'es', 'pl', 'pt', 'ru', 'uk', 'zh'] + : ['cs', 'en', 'bg', 'fr', 'de', 'nl', 'it', 'es', 'pl', 'pt', 'ru', 'uk', 'zh'] + +// @ts-expect-error +export const langsList = getSortedLangs(langs) + export type Languages = typeof langsList[number]['locale'] diff --git a/src/helpers/getSortedLangs/index.tsx b/src/helpers/getSortedLangs/index.tsx new file mode 100644 index 00000000..1b92e767 --- /dev/null +++ b/src/helpers/getSortedLangs/index.tsx @@ -0,0 +1,18 @@ +import { langsOrder } from 'config/languages' + +type TLang = { + className: string, + locale: string, + title: string, +} + +const getOrder = (locale: string) => ( + langsOrder.findIndex((item) => item === locale) +) + +export const getSortedLangs = (langs: Array): Array => { + langs.sort((lang1, lang2) => ( + getOrder(lang1.locale) - getOrder(lang2.locale) + )) + return langs +}