Allow Category definitions to specify language to search in.
This will be entirely up to the homepage maintainer, and will override the user's "Search only in the this language" setting.
This commit is contained in:
parent
778ef649e8
commit
7b85d7a585
5 changed files with 20 additions and 4 deletions
1
flow-typed/homepage.js
vendored
1
flow-typed/homepage.js
vendored
|
@ -25,6 +25,7 @@ declare type RowDataItem = {
|
|||
limitClaimsPerChannel?: number,
|
||||
pageSize?: number,
|
||||
releaseTime?: string,
|
||||
searchLanguages?: Array<string>,
|
||||
},
|
||||
route?: string,
|
||||
hideForUnauth?: boolean,
|
||||
|
|
|
@ -44,6 +44,7 @@ type Props = {
|
|||
showHiddenByUser?: boolean,
|
||||
showNoSourceClaims?: boolean,
|
||||
tileLayout: boolean,
|
||||
searchLanguages?: Array<string>,
|
||||
ignoreSearchInLanguage?: boolean,
|
||||
|
||||
orderBy?: Array<string>, // Trending, New, Top
|
||||
|
@ -165,6 +166,7 @@ function ClaimListDiscover(props: Props) {
|
|||
maxPages,
|
||||
forceShowReposts = false,
|
||||
languageSetting,
|
||||
searchLanguages,
|
||||
searchInLanguage,
|
||||
ignoreSearchInLanguage,
|
||||
limitClaimsPerChannel,
|
||||
|
@ -211,9 +213,14 @@ function ClaimListDiscover(props: Props) {
|
|||
new Set(mutedUris.concat(blockedUris).map((uri) => splitBySeparator(uri)[1]))
|
||||
);
|
||||
|
||||
// Precedence:
|
||||
// - searchLanguages (per instance attribute)
|
||||
// - urlParams
|
||||
// - languageSetting (redux setting)
|
||||
const language = searchLanguages ? searchLanguages.join(',') : languageSetting;
|
||||
const langParam = urlParams.get(CS.LANGUAGE_KEY) || null;
|
||||
const searchInSelectedLangOnly = searchInLanguage && !ignoreSearchInLanguage;
|
||||
const languageParams = resolveLangForClaimSearch(languageSetting, searchInSelectedLangOnly, langParam);
|
||||
const searchInSelectedLangOnly = Boolean(searchLanguages) || (searchInLanguage && !ignoreSearchInLanguage);
|
||||
const languageParams = resolveLangForClaimSearch(language, searchInSelectedLangOnly, langParam);
|
||||
|
||||
let claimTypeParam = claimType || defaultClaimType || null;
|
||||
let streamTypeParam = streamType || defaultStreamType || null;
|
||||
|
|
|
@ -8,7 +8,7 @@ import ClaimListDiscover from 'component/claimListDiscover';
|
|||
import { useIsMobile, useIsLargeScreen } from 'effects/use-screensize';
|
||||
import usePersistedState from 'effects/use-persisted-state';
|
||||
import { getLivestreamUris } from 'util/livestream';
|
||||
import { resolveLangForClaimSearch } from '../../util/default-languages';
|
||||
import { resolveLangForClaimSearch } from 'util/default-languages';
|
||||
|
||||
const DEFAULT_LIVESTREAM_TILE_LIMIT = 8;
|
||||
const SECTION = Object.freeze({ COLLAPSED: 1, EXPANDED: 2 });
|
||||
|
@ -25,6 +25,7 @@ type Props = {
|
|||
channelIds?: Array<string>,
|
||||
activeLivestreams: ?LivestreamInfo,
|
||||
doFetchActiveLivestreams: (orderBy: ?Array<string>, lang: ?Array<string>) => void,
|
||||
searchLanguages?: Array<string>,
|
||||
languageSetting?: string,
|
||||
searchInLanguage?: boolean,
|
||||
langParam?: string | null,
|
||||
|
@ -36,6 +37,7 @@ export default function LivestreamSection(props: Props) {
|
|||
channelIds,
|
||||
activeLivestreams,
|
||||
doFetchActiveLivestreams,
|
||||
searchLanguages,
|
||||
languageSetting,
|
||||
searchInLanguage,
|
||||
langParam,
|
||||
|
@ -66,7 +68,9 @@ export default function LivestreamSection(props: Props) {
|
|||
|
||||
React.useEffect(() => {
|
||||
// Fetch active livestreams on mount
|
||||
const langCsv = resolveLangForClaimSearch(languageSetting, searchInLanguage, langParam);
|
||||
const language = searchLanguages ? searchLanguages.join(',') : languageSetting;
|
||||
const searchInSelectedLangOnly = Boolean(searchLanguages) || searchInLanguage;
|
||||
const langCsv = resolveLangForClaimSearch(language, searchInSelectedLangOnly, langParam);
|
||||
const lang = langCsv ? langCsv.split(',') : null;
|
||||
doFetchActiveLivestreams(CS.ORDER_BY_NEW_VALUE, lang);
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps, (on mount only)
|
||||
|
|
|
@ -115,6 +115,7 @@ function DiscoverPage(props: Props) {
|
|||
channelIds={channelIds}
|
||||
activeLivestreams={activeLivestreams}
|
||||
doFetchActiveLivestreams={doFetchActiveLivestreams}
|
||||
searchLanguages={dynamicRouteProps?.options?.searchLanguages}
|
||||
languageSetting={languageSetting}
|
||||
searchInLanguage={searchInLanguage}
|
||||
langParam={langParam}
|
||||
|
@ -214,6 +215,7 @@ function DiscoverPage(props: Props) {
|
|||
meta={getMeta()}
|
||||
hasSource
|
||||
forceShowReposts={dynamicRouteProps}
|
||||
searchLanguages={dynamicRouteProps?.options?.searchLanguages}
|
||||
/>
|
||||
</Page>
|
||||
);
|
||||
|
|
|
@ -21,6 +21,7 @@ export type HomepageCat = {
|
|||
tags?: Array<string>,
|
||||
pinnedUrls?: Array<string>,
|
||||
pinnedClaimIds?: Array<string>, // takes precedence over pinnedUrls
|
||||
searchLanguages?: Array<string>,
|
||||
mixIn?: Array<string>,
|
||||
};
|
||||
|
||||
|
@ -98,6 +99,7 @@ export const getHomepageRowForCat = (key: string, cat: HomepageCat) => {
|
|||
orderBy: orderValue,
|
||||
pageSize: cat.pageSize || undefined,
|
||||
limitClaimsPerChannel: limitClaims,
|
||||
searchLanguages: cat.searchLanguages,
|
||||
releaseTime: `>${Math.floor(
|
||||
moment()
|
||||
.subtract(cat.daysOfContent || 30, 'days')
|
||||
|
|
Loading…
Reference in a new issue