Revert "Code-split homepages"

This reverts commit 310fc81bd9.

Was breaking the `get` api
This commit is contained in:
infinite-persistence 2021-10-28 01:25:08 +08:00 committed by infinite-persistence
parent 3849683a59
commit 2922f0f2dc
7 changed files with 15 additions and 55 deletions

View file

@ -1,6 +1,3 @@
// Data is lazy-loaded in `doSetHomepage()`
window.odysee_homepages = window.odysee_homepages || {};
module.exports = {
en: null,
en: {},
};

View file

@ -14,7 +14,6 @@ import {
selectLanguage,
selectLoadedLanguages,
selectThemePath,
selectHomepageCode,
} from 'redux/selectors/settings';
import {
selectIsUpgradeAvailable,
@ -23,7 +22,7 @@ import {
selectActiveChannelClaim,
selectIsReloadRequired,
} from 'redux/selectors/app';
import { doGetWalletSyncPreference, doSetLanguage, doSetHomepage } from 'redux/actions/settings';
import { doGetWalletSyncPreference, doSetLanguage } from 'redux/actions/settings';
import { doSyncLoop } from 'redux/actions/sync';
import {
doDownloadUpgradeRequested,
@ -40,7 +39,6 @@ const select = (state) => ({
accessToken: selectAccessToken(state),
theme: selectThemePath(state),
language: selectLanguage(state),
homepageCode: selectHomepageCode(state),
syncEnabled: makeSelectClientSetting(SETTINGS.ENABLE_SYNC)(state),
languages: selectLoadedLanguages(state),
autoUpdateDownloaded: selectAutoUpdateDownloaded(state),
@ -62,7 +60,6 @@ const perform = (dispatch) => ({
fetchChannelListMine: () => dispatch(doFetchChannelListMine()),
fetchCollectionListMine: () => dispatch(doFetchCollectionListMine()),
setLanguage: (language) => dispatch(doSetLanguage(language)),
doSetHomepage: (value) => dispatch(doSetHomepage(value)),
signIn: () => dispatch(doSignIn()),
requestDownloadUpgrade: () => dispatch(doDownloadUpgradeRequested()),
updatePreferences: () => dispatch(doGetAndPopulatePreferences()),

View file

@ -75,7 +75,6 @@ const imaLibraryPath = 'https://imasdk.googleapis.com/js/sdkloader/ima3.js';
type Props = {
language: string,
languages: Array<string>,
homepageCode: string,
theme: string,
user: ?{ id: string, has_verified_email: boolean, is_reward_approved: boolean },
location: { pathname: string, hash: string, search: string },
@ -93,7 +92,6 @@ type Props = {
requestDownloadUpgrade: () => void,
onSignedIn: () => void,
setLanguage: (string) => void,
doSetHomepage: (string) => void,
isUpgradeAvailable: boolean,
isReloadRequired: boolean,
autoUpdateDownloaded: boolean,
@ -137,9 +135,7 @@ function App(props: Props) {
syncError,
language,
languages,
homepageCode,
setLanguage,
doSetHomepage,
updatePreferences,
getWalletSyncPref,
rewards,
@ -316,11 +312,6 @@ function App(props: Props) {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [language, languages]);
// Fetch homepage for the first time
useEffect(() => {
doSetHomepage(homepageCode);
}, []); // eslint-disable-line react-hooks/exhaustive-deps
useEffect(() => {
if (shouldMigrateLanguage) {
setLanguage(shouldMigrateLanguage);

View file

@ -14,7 +14,6 @@ import { doAlertWaitingForSync, doGetAndPopulatePreferences } from 'redux/action
import { selectPrefsReady } from 'redux/selectors/sync';
import { Lbryio } from 'lbryinc';
import { getDefaultLanguage } from 'util/default-languages';
import homepages from 'homepages';
const { DEFAULT_LANGUAGE } = require('config');
const { SDK_SYNC_KEYS } = SHARED_PREFERENCES;
@ -299,22 +298,13 @@ export function doFetchLanguage(language) {
}
export function doSetHomepage(code) {
return async (dispatch, getState) => {
return (dispatch, getState) => {
let languageCode;
if (code === getDefaultLanguage()) {
languageCode = null;
} else {
languageCode = code;
}
const homepage = homepages[code || 'en'];
if (homepage && homepage.lazyLoad) {
const homepageData = await homepage.lazyLoad();
if (homepageData) {
window.odysee_homepages[code || 'en'] = homepageData.default;
}
}
dispatch(doSetClientSetting(SETTINGS.HOMEPAGE, languageCode));
};
}

View file

@ -53,16 +53,21 @@ export const selectThemePath = createSelector(
);
export const selectHomepageCode = createSelector(makeSelectClientSetting(SETTINGS.HOMEPAGE), (setting) => {
return Object.keys(homepages).includes(setting) ? setting : getDefaultHomepageKey();
return homepages[setting] ? setting : getDefaultHomepageKey();
});
export const selectLanguage = createSelector(makeSelectClientSetting(SETTINGS.LANGUAGE), (setting) => {
return setting || getDefaultLanguage();
});
export const selectHomepageData = (state) => {
const homepageCode = selectHomepageCode(state);
return window.odysee_homepages[homepageCode] || {};
};
export const selectHomepageData = createSelector(
// using homepage setting,
selectHomepageCode,
(homepageCode) => {
// homepages = { 'en': homepageFile, ... }
// mixin Homepages here
return homepages[homepageCode] || homepages['en'] || {};
}
);
export const selectosNotificationsEnabled = makeSelectClientSetting(SETTINGS.OS_NOTIFICATIONS_ENABLED);

View file

@ -77,11 +77,9 @@ export const getHomepageRowForCat = (cat: HomepageCat) => {
}
let urlParams = new URLSearchParams();
if (cat.claimType) {
urlParams.set(CS.CLAIM_TYPE, cat.claimType);
}
if (cat.channelIds) {
urlParams.set(CS.CHANNEL_IDS_KEY, cat.channelIds.join(','));
}
@ -90,13 +88,11 @@ export const getHomepageRowForCat = (cat: HomepageCat) => {
// can intend no limit, numerica auto limit, specific limit.
let limitClaims;
if (typeof cat.channelLimit === 'string' && cat.channelIds && cat.channelIds.length) {
if (cat.channelLimit === 'auto') {
limitClaims = getLimitPerChannel(cat.channelIds.length, isChannelType);
} else if (cat.channelLimit) {
const limitNumber = Number(cat.channelLimit);
// eslint-disable-next-line
if (limitNumber === limitNumber && limitNumber !== 0) {
// because javascript and NaN !== NaN
@ -297,11 +293,9 @@ export function GetLinksData(
}),
},
};
// $FlowFixMe flow thinks this might not be Array<string>
rowData.push(RECENT_FROM_FOLLOWING);
}
if (isHomepage && !CUSTOM_HOMEPAGE) {
if (followedTags) {
const TRENDING_FOR_TAGS = {
@ -316,7 +310,6 @@ export function GetLinksData(
limitClaimsPerChannel: 2,
},
};
followedTags.forEach((tag: Tag) => {
const tagName = `#${toCapitalCase(tag.name)}`;
individualTagDataItems.push({
@ -329,11 +322,7 @@ export function GetLinksData(
},
});
});
if (showPersonalizedTags && !showIndividualTags) {
rowData.push(TRENDING_FOR_TAGS);
}
if (showPersonalizedTags && !showIndividualTags) rowData.push(TRENDING_FOR_TAGS);
if (showPersonalizedTags && showIndividualTags) {
individualTagDataItems.forEach((item: RowDataItem) => {
rowData.push(item);
@ -341,7 +330,6 @@ export function GetLinksData(
}
}
}
if (!CUSTOM_HOMEPAGE) {
if (!authenticated) {
rowData.push(YOUTUBE_CREATOR_ROW);
@ -350,7 +338,6 @@ export function GetLinksData(
rowData.push(LATEST_FROM_LBRY);
if (!showPersonalizedChannels) rowData.push(TOP_CHANNELS);
}
// TODO: provide better method for exempting from homepage
(Object.values(all): any)
.filter((row) => !(isHomepage && row.name === 'news'))

View file

@ -10,14 +10,7 @@ export const getDefaultLanguage = () => {
// If homepages has a key "zh-Hant" return that, otherwise return "zh", otherwise "en"
export const getDefaultHomepageKey = () => {
const language = getDefaultLanguage();
const keys = Object.keys(homepages);
if (keys.includes(language)) {
return language;
} else if (keys.includes(language.slice(0, 2))) {
return language.slice(0, 2);
} else {
return DEFAULT_LANG;
}
return (homepages[language] && language) || (homepages[language.slice(0, 2)] && language.slice(0, 2)) || DEFAULT_LANG;
};
/**