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:
parent
f2a63668b7
commit
f27b68587e
4 changed files with 22 additions and 19 deletions
|
@ -2,6 +2,7 @@
|
|||
import React, { useState } from 'react';
|
||||
import classnames from 'classnames';
|
||||
import Icon from 'component/common/icon';
|
||||
import { HOMEPAGE_EXCLUDED_CATEGORIES } from 'constants/homepage_languages';
|
||||
import * as ICONS from 'constants/icons';
|
||||
import 'scss/component/homepage-sort.scss';
|
||||
|
||||
|
@ -48,26 +49,26 @@ function getInitialList(listId, savedOrder, homepageSections) {
|
|||
const savedHiddenOrder = savedOrder.hidden || [];
|
||||
const sectionKeys = Object.keys(homepageSections);
|
||||
|
||||
if (sectionKeys.includes('NEWS') && !savedHiddenOrder.includes('NEWS') && !savedActiveOrder.includes('NEWS')) {
|
||||
savedHiddenOrder.push('NEWS');
|
||||
}
|
||||
|
||||
if (listId === 'ACTIVE') {
|
||||
// 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));
|
||||
|
||||
// Add new items (e.g. new categories)
|
||||
// Add new categories not seen previously.
|
||||
sectionKeys.forEach((x) => {
|
||||
if (!finalOrder.includes(x)) {
|
||||
finalOrder.push(x);
|
||||
}
|
||||
});
|
||||
|
||||
// Exclude items that were moved to Hidden
|
||||
return finalOrder.filter((x) => !savedHiddenOrder.includes(x));
|
||||
// Exclude items that were moved to Hidden, or intentionally excluded from Homepage.
|
||||
return finalOrder
|
||||
.filter((x) => !savedHiddenOrder.includes(x))
|
||||
.filter((x) => !HOMEPAGE_EXCLUDED_CATEGORIES.includes(x));
|
||||
} else {
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -19,3 +19,5 @@ export function getHomepageLanguage(code) {
|
|||
}
|
||||
|
||||
export default HOMEPAGE_LANGUAGES;
|
||||
|
||||
export const HOMEPAGE_EXCLUDED_CATEGORIES = Object.freeze(['NEWS']);
|
||||
|
|
|
@ -84,7 +84,6 @@ function HomePage(props: Props) {
|
|||
showNsfw
|
||||
);
|
||||
|
||||
// TODO: probably need memo, or incorporate into GetLinksData.
|
||||
let sortedRowData: Array<RowDataItem> = [];
|
||||
if (homepageOrder.active && authenticated) {
|
||||
homepageOrder.active.forEach((key) => {
|
||||
|
@ -99,7 +98,7 @@ function HomePage(props: Props) {
|
|||
|
||||
if (homepageOrder.hidden) {
|
||||
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)) {
|
||||
sortedRowData.push(data);
|
||||
}
|
||||
|
@ -107,15 +106,10 @@ function HomePage(props: Props) {
|
|||
}
|
||||
} else {
|
||||
rowData.forEach((key) => {
|
||||
// always inject FYP if homepage not customized, hide news.
|
||||
if (key.id === 'FOLLOWING') {
|
||||
sortedRowData.push(key);
|
||||
if (hasMembership) {
|
||||
if (key.id === 'FOLLOWING' && hasMembership) {
|
||||
sortedRowData.push(FYP_SECTION);
|
||||
}
|
||||
} else if (key.id !== 'NEWS') {
|
||||
sortedRowData.push(key);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
import * as PAGES from 'constants/pages';
|
||||
import * as ICONS from 'constants/icons';
|
||||
import * as CS from 'constants/claim_search';
|
||||
import { HOMEPAGE_EXCLUDED_CATEGORIES } from 'constants/homepage_languages';
|
||||
import { parseURI } from 'util/lbryURI';
|
||||
import moment from 'moment';
|
||||
import { toCapitalCase } from 'util/string';
|
||||
|
@ -110,7 +111,7 @@ export const getHomepageRowForCat = (key: string, cat: HomepageCat) => {
|
|||
export function GetLinksData(
|
||||
all: any, // HomepageData type?
|
||||
isLargeScreen: boolean,
|
||||
isHomepage?: boolean = false,
|
||||
isHomepage?: boolean,
|
||||
authenticated?: boolean,
|
||||
showPersonalizedChannels?: boolean,
|
||||
showPersonalizedTags?: boolean,
|
||||
|
@ -338,6 +339,11 @@ export function GetLinksData(
|
|||
const key = entries[i][0];
|
||||
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
|
||||
rowData.push(getHomepageRowForCat(key, val));
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue