Grab Discover IDs from homepage API

Adds ability for homepage team to define the Discover list of IDs.

If undefined, falls back to English's list. If English is also undefined, falls back to LATEST / PRIMARY.
This commit is contained in:
infinite-persistence 2022-07-12 17:49:08 +08:00 committed by Thomas Zarebczan
parent 9e18b30fdb
commit c563889bf6
4 changed files with 22 additions and 3 deletions

View file

@ -2,7 +2,7 @@ import { connect } from 'react-redux';
import { selectFollowedTags } from 'redux/selectors/tags'; import { selectFollowedTags } from 'redux/selectors/tags';
import { selectMutedChannels } from 'redux/selectors/blocked'; import { selectMutedChannels } from 'redux/selectors/blocked';
import { selectSubscriptions } from 'redux/selectors/subscriptions'; import { selectSubscriptions } from 'redux/selectors/subscriptions';
import { selectHomepageData } from 'redux/selectors/settings'; import { selectHomepageData, selectHomepageDiscover } from 'redux/selectors/settings';
import ChannelsFollowingManagePage from './view'; import ChannelsFollowingManagePage from './view';
const select = (state) => ({ const select = (state) => ({
@ -10,6 +10,7 @@ const select = (state) => ({
subscribedChannels: selectSubscriptions(state), subscribedChannels: selectSubscriptions(state),
blockedChannels: selectMutedChannels(state), blockedChannels: selectMutedChannels(state),
homepageData: selectHomepageData(state), homepageData: selectHomepageData(state),
discoverData: selectHomepageDiscover(state),
}); });
export default connect(select)(ChannelsFollowingManagePage); export default connect(select)(ChannelsFollowingManagePage);

View file

@ -17,6 +17,7 @@ type Props = {
subscribedChannels: Array<Subscription>, subscribedChannels: Array<Subscription>,
blockedChannels: Array<string>, blockedChannels: Array<string>,
homepageData: any, homepageData: any,
discoverData: ?Array<string>,
}; };
type ChannelsFollowingItem = { type ChannelsFollowingItem = {
@ -27,16 +28,20 @@ type ChannelsFollowingItem = {
}; };
function ChannelsFollowingDiscover(props: Props) { function ChannelsFollowingDiscover(props: Props) {
const { followedTags, subscribedChannels, blockedChannels, homepageData } = props; const { followedTags, subscribedChannels, blockedChannels, homepageData, discoverData } = props;
const { PRIMARY_CONTENT, LATEST } = homepageData; const { PRIMARY_CONTENT, LATEST } = homepageData;
let channelIds; let channelIds;
if (CUSTOM_HOMEPAGE) { if (discoverData) {
channelIds = discoverData;
} else if (CUSTOM_HOMEPAGE) {
if (LATEST) { if (LATEST) {
channelIds = LATEST.channelIds; channelIds = LATEST.channelIds;
} else if (PRIMARY_CONTENT) { } else if (PRIMARY_CONTENT) {
channelIds = PRIMARY_CONTENT.channelIds; channelIds = PRIMARY_CONTENT.channelIds;
} }
} }
let rowData: Array<ChannelsFollowingItem> = []; let rowData: Array<ChannelsFollowingItem> = [];
const notChannels = subscribedChannels const notChannels = subscribedChannels
.map(({ uri }) => uri) .map(({ uri }) => uri)

View file

@ -82,6 +82,18 @@ export const selectHomepageMeme = (state) => {
return homepages ? homepages['en'].meme || {} : {}; return homepages ? homepages['en'].meme || {} : {};
}; };
export const selectHomepageDiscover = (state) => {
const homepageCode = selectHomepageCode(state);
const homepages = window.homepages;
if (homepages) {
const discover = homepages[homepageCode].discover;
if (discover) {
return discover;
}
}
return homepages ? homepages['en'].discover || [] : [];
};
export const selectHomepageAnnouncement = (state) => { export const selectHomepageAnnouncement = (state) => {
const homepageCode = selectHomepageCode(state); const homepageCode = selectHomepageCode(state);
const homepages = window.homepages; const homepages = window.homepages;

View file

@ -65,6 +65,7 @@ const getHomepageJsonV2 = (format) => {
v2[hp] = { v2[hp] = {
categories: reformatV2Categories(memo.homepageData[hp].categories, format), categories: reformatV2Categories(memo.homepageData[hp].categories, format),
meme: memo.homepageData[hp].meme, meme: memo.homepageData[hp].meme,
discover: memo.homepageData[hp].discover,
announcement: memo.announcements[hp], announcement: memo.announcements[hp],
}; };
}); });