From c6d8687cfa84cf98d682cf4e13f716b4d5fa3710 Mon Sep 17 00:00:00 2001 From: infinite-persistence Date: Thu, 24 Feb 2022 18:06:38 +0800 Subject: [PATCH] ClaimListDiscover: pull out 'claim_search' language code for re-use, so all clients are sending the same value. No functional change. --- ui/component/claimListDiscover/view.jsx | 15 +++------------ ui/util/default-languages.js | 23 +++++++++++++++++++++++ 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/ui/component/claimListDiscover/view.jsx b/ui/component/claimListDiscover/view.jsx index 4abbc0b50..9e94fa2a0 100644 --- a/ui/component/claimListDiscover/view.jsx +++ b/ui/component/claimListDiscover/view.jsx @@ -6,6 +6,7 @@ import React from 'react'; import usePersistedState from 'effects/use-persisted-state'; import { withRouter } from 'react-router'; import { MATURE_TAGS } from 'constants/tags'; +import { resolveLangForClaimSearch } from 'util/default-languages'; import { createNormalizedClaimSearchKey } from 'util/claim'; import { splitBySeparator } from 'util/lbryURI'; import Button from 'component/button'; @@ -195,18 +196,8 @@ function ClaimListDiscover(props: Props) { ); const langParam = urlParams.get(CS.LANGUAGE_KEY) || null; - const languageParams = - searchInLanguage && !ignoreSearchInLanguage - ? langParam === null - ? languageSetting.concat(languageSetting === 'en' ? ',none' : '') - : langParam === 'any' - ? null - : langParam.concat(langParam === 'en' ? ',none' : '') - : langParam === null - ? null - : langParam === 'any' - ? null - : langParam.concat(langParam === 'en' ? ',none' : ''); + const searchInSelectedLangOnly = searchInLanguage && !ignoreSearchInLanguage; + const languageParams = resolveLangForClaimSearch(languageSetting, searchInSelectedLangOnly, langParam); let claimTypeParam = claimType || defaultClaimType || null; let streamTypeParam = streamType || defaultStreamType || null; diff --git a/ui/util/default-languages.js b/ui/util/default-languages.js index e18213724..e6597b2db 100644 --- a/ui/util/default-languages.js +++ b/ui/util/default-languages.js @@ -42,3 +42,26 @@ export function sortLanguageMap(languages) { return 0; }); } + +/** + * Resolves the language parameter for a claim_search based on various settings. + * + * @param langSetting The user's language setting. + * @param searchInSelectedLangOnly Return results in the given language only. + * @param langParam Language override for specific use-cases, typically from urlParam. + * @returns {string|null} Comma-separated string of language codes, or null. + */ +export function resolveLangForClaimSearch(langSetting, searchInSelectedLangOnly, langParam = null) { + // TODO: expand ternary for easier maintenance. + return searchInSelectedLangOnly + ? langParam === null + ? langSetting.concat(langSetting === 'en' ? ',none' : '') + : langParam === 'any' + ? null + : langParam.concat(langParam === 'en' ? ',none' : '') + : langParam === null + ? null + : langParam === 'any' + ? null + : langParam.concat(langParam === 'en' ? ',none' : ''); +}