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,
pageSize?: number,
releaseTime?: string,
searchLanguages?: Array<string>,
},
route?: string,
hideForUnauth?: boolean,

View file

@ -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;

View file

@ -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)

View file

@ -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>
);

View file

@ -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')