Restore original way to exclude categories in Homepage

It was previously done in `GetLinkData`, but accidentally removed in d854a992.
It is DRY-er to do it here rather than at the client side.

Also needed to filter in the homepage-sort dialog, so move the definition to a constant array.
This commit is contained in:
infinite-persistence 2022-04-19 14:09:57 +08:00
parent f2a63668b7
commit f27b68587e
No known key found for this signature in database
GPG key ID: B9C3252EDC3D0AA0
4 changed files with 22 additions and 19 deletions

View file

@ -2,6 +2,7 @@
import React, { useState } from 'react'; import React, { useState } from 'react';
import classnames from 'classnames'; import classnames from 'classnames';
import Icon from 'component/common/icon'; import Icon from 'component/common/icon';
import { HOMEPAGE_EXCLUDED_CATEGORIES } from 'constants/homepage_languages';
import * as ICONS from 'constants/icons'; import * as ICONS from 'constants/icons';
import 'scss/component/homepage-sort.scss'; import 'scss/component/homepage-sort.scss';
@ -48,26 +49,26 @@ function getInitialList(listId, savedOrder, homepageSections) {
const savedHiddenOrder = savedOrder.hidden || []; const savedHiddenOrder = savedOrder.hidden || [];
const sectionKeys = Object.keys(homepageSections); const sectionKeys = Object.keys(homepageSections);
if (sectionKeys.includes('NEWS') && !savedHiddenOrder.includes('NEWS') && !savedActiveOrder.includes('NEWS')) {
savedHiddenOrder.push('NEWS');
}
if (listId === 'ACTIVE') { if (listId === 'ACTIVE') {
// Start with saved order, excluding obsolete items (i.e. category removed or not available in non-English) // Start with saved order, excluding obsolete items (i.e. category removed or not available in non-English)
const finalOrder = savedActiveOrder.filter((x) => sectionKeys.includes(x)); const finalOrder = savedActiveOrder.filter((x) => sectionKeys.includes(x));
// Add new items (e.g. new categories) // Add new categories not seen previously.
sectionKeys.forEach((x) => { sectionKeys.forEach((x) => {
if (!finalOrder.includes(x)) { if (!finalOrder.includes(x)) {
finalOrder.push(x); finalOrder.push(x);
} }
}); });
// Exclude items that were moved to Hidden // Exclude items that were moved to Hidden, or intentionally excluded from Homepage.
return finalOrder.filter((x) => !savedHiddenOrder.includes(x)); return finalOrder
.filter((x) => !savedHiddenOrder.includes(x))
.filter((x) => !HOMEPAGE_EXCLUDED_CATEGORIES.includes(x));
} else { } else {
console.assert(listId === 'HIDDEN', `Unhandled listId: ${listId}`); console.assert(listId === 'HIDDEN', `Unhandled listId: ${listId}`);
return savedHiddenOrder.filter((x) => sectionKeys.includes(x)); return savedHiddenOrder
.filter((x) => sectionKeys.includes(x))
.filter((x) => !HOMEPAGE_EXCLUDED_CATEGORIES.includes(x));
} }
} }

View file

@ -19,3 +19,5 @@ export function getHomepageLanguage(code) {
} }
export default HOMEPAGE_LANGUAGES; export default HOMEPAGE_LANGUAGES;
export const HOMEPAGE_EXCLUDED_CATEGORIES = Object.freeze(['NEWS']);

View file

@ -84,7 +84,6 @@ function HomePage(props: Props) {
showNsfw showNsfw
); );
// TODO: probably need memo, or incorporate into GetLinksData.
let sortedRowData: Array<RowDataItem> = []; let sortedRowData: Array<RowDataItem> = [];
if (homepageOrder.active && authenticated) { if (homepageOrder.active && authenticated) {
homepageOrder.active.forEach((key) => { homepageOrder.active.forEach((key) => {
@ -99,7 +98,7 @@ function HomePage(props: Props) {
if (homepageOrder.hidden) { if (homepageOrder.hidden) {
rowData.forEach((data: RowDataItem) => { rowData.forEach((data: RowDataItem) => {
// $FlowIssue: null 'hidden' already avoided, but flow can't see beyond this anonymous function? // $FlowIssue: null 'hidden' already avoided outside anonymous function.
if (!homepageOrder.hidden.includes(data.id)) { if (!homepageOrder.hidden.includes(data.id)) {
sortedRowData.push(data); sortedRowData.push(data);
} }
@ -107,14 +106,9 @@ function HomePage(props: Props) {
} }
} else { } else {
rowData.forEach((key) => { rowData.forEach((key) => {
// always inject FYP if homepage not customized, hide news. sortedRowData.push(key);
if (key.id === 'FOLLOWING') { if (key.id === 'FOLLOWING' && hasMembership) {
sortedRowData.push(key); sortedRowData.push(FYP_SECTION);
if (hasMembership) {
sortedRowData.push(FYP_SECTION);
}
} else if (key.id !== 'NEWS') {
sortedRowData.push(key);
} }
}); });
} }

View file

@ -2,6 +2,7 @@
import * as PAGES from 'constants/pages'; import * as PAGES from 'constants/pages';
import * as ICONS from 'constants/icons'; import * as ICONS from 'constants/icons';
import * as CS from 'constants/claim_search'; import * as CS from 'constants/claim_search';
import { HOMEPAGE_EXCLUDED_CATEGORIES } from 'constants/homepage_languages';
import { parseURI } from 'util/lbryURI'; import { parseURI } from 'util/lbryURI';
import moment from 'moment'; import moment from 'moment';
import { toCapitalCase } from 'util/string'; import { toCapitalCase } from 'util/string';
@ -110,7 +111,7 @@ export const getHomepageRowForCat = (key: string, cat: HomepageCat) => {
export function GetLinksData( export function GetLinksData(
all: any, // HomepageData type? all: any, // HomepageData type?
isLargeScreen: boolean, isLargeScreen: boolean,
isHomepage?: boolean = false, isHomepage?: boolean,
authenticated?: boolean, authenticated?: boolean,
showPersonalizedChannels?: boolean, showPersonalizedChannels?: boolean,
showPersonalizedTags?: boolean, showPersonalizedTags?: boolean,
@ -338,6 +339,11 @@ export function GetLinksData(
const key = entries[i][0]; const key = entries[i][0];
const val = entries[i][1]; const val = entries[i][1];
// $FlowFixMe https://github.com/facebook/flow/issues/2221
if (isHomepage && HOMEPAGE_EXCLUDED_CATEGORIES.includes(key)) {
continue;
}
// $FlowFixMe https://github.com/facebook/flow/issues/2221 // $FlowFixMe https://github.com/facebook/flow/issues/2221
rowData.push(getHomepageRowForCat(key, val)); rowData.push(getHomepageRowForCat(key, val));
} }