Support homepage-specific memes
1446 - Requires an accompanying commit in `odysee-frontend`. - The change assumes that the `odysee-frontend` is the only project that uses these files directly, i.e. other clients will use the API instead.
This commit is contained in:
parent
17868635bd
commit
8874008245
6 changed files with 31 additions and 24 deletions
|
@ -7,7 +7,12 @@ import { selectActiveLivestreams, selectFetchingActiveLivestreams } from 'redux/
|
||||||
import { selectFollowedTags } from 'redux/selectors/tags';
|
import { selectFollowedTags } from 'redux/selectors/tags';
|
||||||
import { selectHasOdyseeMembership, selectHomepageFetched, selectUserVerifiedEmail } from 'redux/selectors/user';
|
import { selectHasOdyseeMembership, selectHomepageFetched, selectUserVerifiedEmail } from 'redux/selectors/user';
|
||||||
import { selectSubscriptions } from 'redux/selectors/subscriptions';
|
import { selectSubscriptions } from 'redux/selectors/subscriptions';
|
||||||
import { selectShowMatureContent, selectHomepageData, selectClientSetting } from 'redux/selectors/settings';
|
import {
|
||||||
|
selectShowMatureContent,
|
||||||
|
selectHomepageData,
|
||||||
|
selectClientSetting,
|
||||||
|
selectHomepageMeme,
|
||||||
|
} from 'redux/selectors/settings';
|
||||||
|
|
||||||
import HomePage from './view';
|
import HomePage from './view';
|
||||||
|
|
||||||
|
@ -17,6 +22,7 @@ const select = (state) => ({
|
||||||
authenticated: selectUserVerifiedEmail(state),
|
authenticated: selectUserVerifiedEmail(state),
|
||||||
showNsfw: selectShowMatureContent(state),
|
showNsfw: selectShowMatureContent(state),
|
||||||
homepageData: selectHomepageData(state),
|
homepageData: selectHomepageData(state),
|
||||||
|
homepageMeme: selectHomepageMeme(state),
|
||||||
homepageFetched: selectHomepageFetched(state),
|
homepageFetched: selectHomepageFetched(state),
|
||||||
activeLivestreams: selectActiveLivestreams(state),
|
activeLivestreams: selectActiveLivestreams(state),
|
||||||
fetchingActiveLivestreams: selectFetchingActiveLivestreams(state),
|
fetchingActiveLivestreams: selectFetchingActiveLivestreams(state),
|
||||||
|
|
|
@ -36,6 +36,7 @@ type Props = {
|
||||||
subscribedChannels: Array<Subscription>,
|
subscribedChannels: Array<Subscription>,
|
||||||
showNsfw: boolean,
|
showNsfw: boolean,
|
||||||
homepageData: any,
|
homepageData: any,
|
||||||
|
homepageMeme: ?{ text: string, url: string },
|
||||||
homepageFetched: boolean,
|
homepageFetched: boolean,
|
||||||
activeLivestreams: any,
|
activeLivestreams: any,
|
||||||
doFetchActiveLivestreams: () => void,
|
doFetchActiveLivestreams: () => void,
|
||||||
|
@ -54,6 +55,7 @@ function HomePage(props: Props) {
|
||||||
authenticated,
|
authenticated,
|
||||||
showNsfw,
|
showNsfw,
|
||||||
homepageData,
|
homepageData,
|
||||||
|
homepageMeme,
|
||||||
homepageFetched,
|
homepageFetched,
|
||||||
activeLivestreams,
|
activeLivestreams,
|
||||||
doFetchActiveLivestreams,
|
doFetchActiveLivestreams,
|
||||||
|
@ -226,7 +228,7 @@ function HomePage(props: Props) {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Page className="homePage-wrapper" fullWidthPage>
|
<Page className="homePage-wrapper" fullWidthPage>
|
||||||
<Meme />
|
<Meme meme={homepageMeme} />
|
||||||
|
|
||||||
{!fetchingActiveLivestreams && (
|
{!fetchingActiveLivestreams && (
|
||||||
<>
|
<>
|
||||||
|
|
|
@ -325,18 +325,10 @@ export function doFetchHomepages() {
|
||||||
if (homepages) {
|
if (homepages) {
|
||||||
const v2 = {};
|
const v2 = {};
|
||||||
const homepageKeys = Object.keys(homepages);
|
const homepageKeys = Object.keys(homepages);
|
||||||
|
|
||||||
homepageKeys.forEach((hp) => {
|
homepageKeys.forEach((hp) => {
|
||||||
v2[hp] = {
|
v2[hp] = homepages[hp];
|
||||||
categories: homepages[hp],
|
|
||||||
};
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const meme = require('memes');
|
|
||||||
if (meme && v2['en']) {
|
|
||||||
v2['en'].meme = meme;
|
|
||||||
}
|
|
||||||
|
|
||||||
window.homepages = v2;
|
window.homepages = v2;
|
||||||
populateCategoryTitles(window.homepages?.en?.categories);
|
populateCategoryTitles(window.homepages?.en?.categories);
|
||||||
dispatch({ type: ACTIONS.FETCH_HOMEPAGES_DONE });
|
dispatch({ type: ACTIONS.FETCH_HOMEPAGES_DONE });
|
||||||
|
|
|
@ -70,6 +70,18 @@ export const selectHomepageData = (state) => {
|
||||||
return homepages ? homepages[homepageCode].categories || homepages['en'].categories || {} : {};
|
return homepages ? homepages[homepageCode].categories || homepages['en'].categories || {} : {};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const selectHomepageMeme = (state) => {
|
||||||
|
const homepageCode = selectHomepageCode(state);
|
||||||
|
const homepages = window.homepages;
|
||||||
|
if (homepages) {
|
||||||
|
const meme = homepages[homepageCode].meme;
|
||||||
|
if (meme && meme.text && meme.url) {
|
||||||
|
return meme;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return homepages['en'].meme || {};
|
||||||
|
};
|
||||||
|
|
||||||
export const selectInRegionByCode = (state, code) => {
|
export const selectInRegionByCode = (state, code) => {
|
||||||
const hp = selectClientSetting(state, SETTINGS.HOMEPAGE);
|
const hp = selectClientSetting(state, SETTINGS.HOMEPAGE);
|
||||||
const lang = selectLanguage(state);
|
const lang = selectLanguage(state);
|
||||||
|
|
|
@ -1,8 +1,13 @@
|
||||||
|
// @flow
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import Button from 'component/button';
|
import Button from 'component/button';
|
||||||
|
|
||||||
export default function Meme() {
|
type Props = {
|
||||||
const meme = window?.homepages?.en?.meme;
|
meme: ?{ text: string, url: string },
|
||||||
|
};
|
||||||
|
|
||||||
|
export default function Meme(props: Props) {
|
||||||
|
const { meme } = props;
|
||||||
if (!meme) {
|
if (!meme) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,6 @@ const memo = {};
|
||||||
if (!memo.homepageData) {
|
if (!memo.homepageData) {
|
||||||
try {
|
try {
|
||||||
memo.homepageData = require('../../custom/homepages/v2');
|
memo.homepageData = require('../../custom/homepages/v2');
|
||||||
memo.meme = require('../../custom/homepages/meme');
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log('getHomepageJSON:', err);
|
console.log('getHomepageJSON:', err);
|
||||||
}
|
}
|
||||||
|
@ -21,18 +20,9 @@ const getHomepageJsonV2 = () => {
|
||||||
|
|
||||||
const v2 = {};
|
const v2 = {};
|
||||||
const homepageKeys = Object.keys(memo.homepageData);
|
const homepageKeys = Object.keys(memo.homepageData);
|
||||||
|
|
||||||
homepageKeys.forEach((hp) => {
|
homepageKeys.forEach((hp) => {
|
||||||
v2[hp] = {
|
v2[hp] = memo.homepageData[hp];
|
||||||
categories: memo.homepageData[hp],
|
|
||||||
};
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (memo.meme && v2['en']) {
|
|
||||||
// Only supporting English memes for now, but one-per-homepage is possible.
|
|
||||||
v2['en'].meme = memo.meme;
|
|
||||||
}
|
|
||||||
|
|
||||||
return v2;
|
return v2;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue