ClaimListDiscover: pull out 'claim_search' language code for re-use, so all clients are sending the same value. No functional change.
This commit is contained in:
parent
f1fdfcd329
commit
c6d8687cfa
2 changed files with 26 additions and 12 deletions
|
@ -6,6 +6,7 @@ import React from 'react';
|
||||||
import usePersistedState from 'effects/use-persisted-state';
|
import usePersistedState from 'effects/use-persisted-state';
|
||||||
import { withRouter } from 'react-router';
|
import { withRouter } from 'react-router';
|
||||||
import { MATURE_TAGS } from 'constants/tags';
|
import { MATURE_TAGS } from 'constants/tags';
|
||||||
|
import { resolveLangForClaimSearch } from 'util/default-languages';
|
||||||
import { createNormalizedClaimSearchKey } from 'util/claim';
|
import { createNormalizedClaimSearchKey } from 'util/claim';
|
||||||
import { splitBySeparator } from 'util/lbryURI';
|
import { splitBySeparator } from 'util/lbryURI';
|
||||||
import Button from 'component/button';
|
import Button from 'component/button';
|
||||||
|
@ -195,18 +196,8 @@ function ClaimListDiscover(props: Props) {
|
||||||
);
|
);
|
||||||
|
|
||||||
const langParam = urlParams.get(CS.LANGUAGE_KEY) || null;
|
const langParam = urlParams.get(CS.LANGUAGE_KEY) || null;
|
||||||
const languageParams =
|
const searchInSelectedLangOnly = searchInLanguage && !ignoreSearchInLanguage;
|
||||||
searchInLanguage && !ignoreSearchInLanguage
|
const languageParams = resolveLangForClaimSearch(languageSetting, searchInSelectedLangOnly, langParam);
|
||||||
? 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' : '');
|
|
||||||
|
|
||||||
let claimTypeParam = claimType || defaultClaimType || null;
|
let claimTypeParam = claimType || defaultClaimType || null;
|
||||||
let streamTypeParam = streamType || defaultStreamType || null;
|
let streamTypeParam = streamType || defaultStreamType || null;
|
||||||
|
|
|
@ -42,3 +42,26 @@ export function sortLanguageMap(languages) {
|
||||||
return 0;
|
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' : '');
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue