Inject ID into homepage data

This will be used to sorting.
This commit is contained in:
infinite-persistence 2022-03-23 16:41:15 +08:00 committed by Thomas Zarebczan
parent aeb475ec2e
commit d854a99250
2 changed files with 14 additions and 25 deletions

View file

@ -12,6 +12,7 @@ declare type HomepageData = {
}; };
declare type RowDataItem = { declare type RowDataItem = {
id: string,
title: any, title: any,
link?: string, link?: string,
help?: any, help?: any,

View file

@ -7,21 +7,6 @@ import moment from 'moment';
import { toCapitalCase } from 'util/string'; import { toCapitalCase } from 'util/string';
import { CUSTOM_HOMEPAGE } from 'config'; import { CUSTOM_HOMEPAGE } from 'config';
export type RowDataItem = {
title: any,
link?: string,
help?: any,
icon?: string,
extra?: any,
options?: {
channelIds?: Array<string>,
pageSize?: number,
limitClaimsPerChannel?: number,
},
route?: string,
hideForUnauth?: boolean,
};
export type HomepageCat = { export type HomepageCat = {
name: string, name: string,
icon: string, icon: string,
@ -37,12 +22,6 @@ export type HomepageCat = {
mixIn?: Array<string>, mixIn?: Array<string>,
}; };
// type HomepageData = {
// [string]: {
// [string]: HomepageCat,
// },
// };
function getLimitPerChannel(size, isChannel) { function getLimitPerChannel(size, isChannel) {
if (isChannel) { if (isChannel) {
return 1; return 1;
@ -62,7 +41,7 @@ export function getAllIds(all: any) {
return Array.from(idsSet); return Array.from(idsSet);
} }
export const getHomepageRowForCat = (cat: HomepageCat) => { export const getHomepageRowForCat = (key: string, cat: HomepageCat) => {
let orderValue; let orderValue;
switch (cat.order) { switch (cat.order) {
case 'trending': case 'trending':
@ -104,6 +83,7 @@ export const getHomepageRowForCat = (cat: HomepageCat) => {
} }
return { return {
id: key,
link: `/$/${PAGES.DISCOVER}?${urlParams.toString()}`, link: `/$/${PAGES.DISCOVER}?${urlParams.toString()}`,
route: cat.name ? `/$/${cat.name}` : undefined, route: cat.name ? `/$/${cat.name}` : undefined,
icon: cat.icon || '', // some default icon: cat.icon || '', // some default
@ -147,6 +127,7 @@ export function GetLinksData(
if (isHomepage && showPersonalizedChannels && subscribedChannels) { if (isHomepage && showPersonalizedChannels && subscribedChannels) {
const RECENT_FROM_FOLLOWING = { const RECENT_FROM_FOLLOWING = {
id: 'FOLLOWING',
title: __('Recent From Following'), title: __('Recent From Following'),
link: `/$/${PAGES.CHANNELS_FOLLOWING}`, link: `/$/${PAGES.CHANNELS_FOLLOWING}`,
icon: ICONS.SUBSCRIBE, icon: ICONS.SUBSCRIBE,
@ -318,6 +299,7 @@ export function GetLinksData(
followedTags.forEach((tag: Tag) => { followedTags.forEach((tag: Tag) => {
const tagName = `#${toCapitalCase(tag.name)}`; const tagName = `#${toCapitalCase(tag.name)}`;
individualTagDataItems.push({ individualTagDataItems.push({
id: tagName,
title: __('Trending for %tagName%', { tagName: tagName }), title: __('Trending for %tagName%', { tagName: tagName }),
link: `/$/${PAGES.DISCOVER}?t=${tag.name}`, link: `/$/${PAGES.DISCOVER}?t=${tag.name}`,
options: { options: {
@ -349,8 +331,14 @@ export function GetLinksData(
// ************************************************************************** // **************************************************************************
// TODO: provide better method for exempting from homepage // TODO: provide better method for exempting from homepage
(Object.values(all): any) const entries = Object.entries(all);
.filter((row) => !(isHomepage && row.name === 'news')) for (let i = 0; i < entries.length; ++i) {
.map((row) => rowData.push(getHomepageRowForCat(row))); const key = entries[i][0];
const val = entries[i][1];
// $FlowFixMe https://github.com/facebook/flow/issues/2221
rowData.push(getHomepageRowForCat(key, val));
}
return rowData; return rowData;
} }