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:
infinite-persistence 2022-04-19 20:56:28 +08:00
parent 778ef649e8
commit 7b85d7a585
No known key found for this signature in database
GPG key ID: B9C3252EDC3D0AA0
5 changed files with 20 additions and 4 deletions

View file

@ -25,6 +25,7 @@ declare type RowDataItem = {
limitClaimsPerChannel?: number, limitClaimsPerChannel?: number,
pageSize?: number, pageSize?: number,
releaseTime?: string, releaseTime?: string,
searchLanguages?: Array<string>,
}, },
route?: string, route?: string,
hideForUnauth?: boolean, hideForUnauth?: boolean,

View file

@ -44,6 +44,7 @@ type Props = {
showHiddenByUser?: boolean, showHiddenByUser?: boolean,
showNoSourceClaims?: boolean, showNoSourceClaims?: boolean,
tileLayout: boolean, tileLayout: boolean,
searchLanguages?: Array<string>,
ignoreSearchInLanguage?: boolean, ignoreSearchInLanguage?: boolean,
orderBy?: Array<string>, // Trending, New, Top orderBy?: Array<string>, // Trending, New, Top
@ -165,6 +166,7 @@ function ClaimListDiscover(props: Props) {
maxPages, maxPages,
forceShowReposts = false, forceShowReposts = false,
languageSetting, languageSetting,
searchLanguages,
searchInLanguage, searchInLanguage,
ignoreSearchInLanguage, ignoreSearchInLanguage,
limitClaimsPerChannel, limitClaimsPerChannel,
@ -211,9 +213,14 @@ function ClaimListDiscover(props: Props) {
new Set(mutedUris.concat(blockedUris).map((uri) => splitBySeparator(uri)[1])) 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 langParam = urlParams.get(CS.LANGUAGE_KEY) || null;
const searchInSelectedLangOnly = searchInLanguage && !ignoreSearchInLanguage; const searchInSelectedLangOnly = Boolean(searchLanguages) || (searchInLanguage && !ignoreSearchInLanguage);
const languageParams = resolveLangForClaimSearch(languageSetting, searchInSelectedLangOnly, langParam); const languageParams = resolveLangForClaimSearch(language, searchInSelectedLangOnly, langParam);
let claimTypeParam = claimType || defaultClaimType || null; let claimTypeParam = claimType || defaultClaimType || null;
let streamTypeParam = streamType || defaultStreamType || null; let streamTypeParam = streamType || defaultStreamType || null;

View file

@ -8,7 +8,7 @@ import ClaimListDiscover from 'component/claimListDiscover';
import { useIsMobile, useIsLargeScreen } from 'effects/use-screensize'; import { useIsMobile, useIsLargeScreen } from 'effects/use-screensize';
import usePersistedState from 'effects/use-persisted-state'; import usePersistedState from 'effects/use-persisted-state';
import { getLivestreamUris } from 'util/livestream'; import { getLivestreamUris } from 'util/livestream';
import { resolveLangForClaimSearch } from '../../util/default-languages'; import { resolveLangForClaimSearch } from 'util/default-languages';
const DEFAULT_LIVESTREAM_TILE_LIMIT = 8; const DEFAULT_LIVESTREAM_TILE_LIMIT = 8;
const SECTION = Object.freeze({ COLLAPSED: 1, EXPANDED: 2 }); const SECTION = Object.freeze({ COLLAPSED: 1, EXPANDED: 2 });
@ -25,6 +25,7 @@ type Props = {
channelIds?: Array<string>, channelIds?: Array<string>,
activeLivestreams: ?LivestreamInfo, activeLivestreams: ?LivestreamInfo,
doFetchActiveLivestreams: (orderBy: ?Array<string>, lang: ?Array<string>) => void, doFetchActiveLivestreams: (orderBy: ?Array<string>, lang: ?Array<string>) => void,
searchLanguages?: Array<string>,
languageSetting?: string, languageSetting?: string,
searchInLanguage?: boolean, searchInLanguage?: boolean,
langParam?: string | null, langParam?: string | null,
@ -36,6 +37,7 @@ export default function LivestreamSection(props: Props) {
channelIds, channelIds,
activeLivestreams, activeLivestreams,
doFetchActiveLivestreams, doFetchActiveLivestreams,
searchLanguages,
languageSetting, languageSetting,
searchInLanguage, searchInLanguage,
langParam, langParam,
@ -66,7 +68,9 @@ export default function LivestreamSection(props: Props) {
React.useEffect(() => { React.useEffect(() => {
// Fetch active livestreams on mount // 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; const lang = langCsv ? langCsv.split(',') : null;
doFetchActiveLivestreams(CS.ORDER_BY_NEW_VALUE, lang); doFetchActiveLivestreams(CS.ORDER_BY_NEW_VALUE, lang);
// eslint-disable-next-line react-hooks/exhaustive-deps, (on mount only) // eslint-disable-next-line react-hooks/exhaustive-deps, (on mount only)

View file

@ -115,6 +115,7 @@ function DiscoverPage(props: Props) {
channelIds={channelIds} channelIds={channelIds}
activeLivestreams={activeLivestreams} activeLivestreams={activeLivestreams}
doFetchActiveLivestreams={doFetchActiveLivestreams} doFetchActiveLivestreams={doFetchActiveLivestreams}
searchLanguages={dynamicRouteProps?.options?.searchLanguages}
languageSetting={languageSetting} languageSetting={languageSetting}
searchInLanguage={searchInLanguage} searchInLanguage={searchInLanguage}
langParam={langParam} langParam={langParam}
@ -214,6 +215,7 @@ function DiscoverPage(props: Props) {
meta={getMeta()} meta={getMeta()}
hasSource hasSource
forceShowReposts={dynamicRouteProps} forceShowReposts={dynamicRouteProps}
searchLanguages={dynamicRouteProps?.options?.searchLanguages}
/> />
</Page> </Page>
); );

View file

@ -21,6 +21,7 @@ export type HomepageCat = {
tags?: Array<string>, tags?: Array<string>,
pinnedUrls?: Array<string>, pinnedUrls?: Array<string>,
pinnedClaimIds?: Array<string>, // takes precedence over pinnedUrls pinnedClaimIds?: Array<string>, // takes precedence over pinnedUrls
searchLanguages?: Array<string>,
mixIn?: Array<string>, mixIn?: Array<string>,
}; };
@ -98,6 +99,7 @@ export const getHomepageRowForCat = (key: string, cat: HomepageCat) => {
orderBy: orderValue, orderBy: orderValue,
pageSize: cat.pageSize || undefined, pageSize: cat.pageSize || undefined,
limitClaimsPerChannel: limitClaims, limitClaimsPerChannel: limitClaims,
searchLanguages: cat.searchLanguages,
releaseTime: `>${Math.floor( releaseTime: `>${Math.floor(
moment() moment()
.subtract(cat.daysOfContent || 30, 'days') .subtract(cat.daysOfContent || 30, 'days')