Simplify ad-injection logic

Since `<Ads>` is already checking against SHOW_ADS and membershipship details, there is no need for all clients to repeat the same thing.
This commit is contained in:
infinite-persistence 2022-03-10 19:44:11 +08:00
parent 803a779e9e
commit 2dd0fc283d
No known key found for this signature in database
GPG key ID: B9C3252EDC3D0AA0
8 changed files with 10 additions and 35 deletions

View file

@ -11,7 +11,6 @@ import { doResolveUris } from 'redux/actions/claims';
import * as SETTINGS from 'constants/settings';
import { makeSelectChannelIsMuted } from 'redux/selectors/blocked';
import { withRouter } from 'react-router';
import { selectOdyseeMembershipIsPremiumPlus } from 'redux/selectors/user';
import { selectClientSetting, selectShowMatureContent } from 'redux/selectors/settings';
import { doFetchChannelLiveStatus } from 'redux/actions/livestream';
import { selectActiveLivestreamForChannel, selectActiveLivestreamInitialized } from 'redux/selectors/livestream';
@ -36,7 +35,6 @@ const select = (state, props) => {
tileLayout: selectClientSetting(state, SETTINGS.TILE_LAYOUT),
activeLivestreamForChannel: selectActiveLivestreamForChannel(state, channelClaimId),
activeLivestreamInitialized: selectActiveLivestreamInitialized(state),
userHasPremiumPlus: selectOdyseeMembershipIsPremiumPlus(state),
};
};

View file

@ -1,5 +1,5 @@
// @flow
import { SHOW_ADS, SIMPLE_SITE } from 'config';
import { SIMPLE_SITE } from 'config';
import * as CS from 'constants/claim_search';
import * as ICONS from 'constants/icons';
import React, { Fragment } from 'react';
@ -39,7 +39,6 @@ type Props = {
doFetchChannelLiveStatus: (string) => void,
activeLivestreamForChannel: any,
activeLivestreamInitialized: boolean,
userHasPremiumPlus: boolean,
};
function ChannelContent(props: Props) {
@ -61,7 +60,6 @@ function ChannelContent(props: Props) {
doFetchChannelLiveStatus,
activeLivestreamForChannel,
activeLivestreamInitialized,
userHasPremiumPlus,
} = props;
// const claimsInChannel = (claim && claim.meta.claims_in_channel) || 0;
@ -162,7 +160,7 @@ function ChannelContent(props: Props) {
defaultOrderBy={CS.ORDER_BY_NEW}
pageSize={defaultPageSize}
infiniteScroll={defaultInfiniteScroll}
injectedItem={SHOW_ADS && !userHasPremiumPlus && { node: <Ads type="video" tileLayout={tileLayout} small /> }}
injectedItem={{ node: <Ads type="video" tileLayout={tileLayout} small /> }}
meta={
showFilters && (
<Form onSubmit={() => {}} className="wunderbar--inline">

View file

@ -5,7 +5,6 @@ import { makeSelectClaimForUri } from 'redux/selectors/claims';
import * as SETTINGS from 'constants/settings';
import { doFetchActiveLivestreams } from 'redux/actions/livestream';
import { selectActiveLivestreams } from 'redux/selectors/livestream';
import { selectOdyseeMembershipIsPremiumPlus } from 'redux/selectors/user';
import { selectFollowedTags } from 'redux/selectors/tags';
import { doToggleTagFollowDesktop } from 'redux/actions/tags';
import { selectClientSetting, selectLanguage } from 'redux/selectors/settings';
@ -22,7 +21,6 @@ const select = (state, props) => {
repostedClaim: repostedUri ? makeSelectClaimForUri(repostedUri)(state) : null,
tileLayout: selectClientSetting(state, SETTINGS.TILE_LAYOUT),
activeLivestreams: selectActiveLivestreams(state),
userHasPremiumPlus: selectOdyseeMembershipIsPremiumPlus(state),
languageSetting: selectLanguage(state),
searchInLanguage: selectClientSetting(state, SETTINGS.SEARCH_IN_LANGUAGE),
};

View file

@ -1,5 +1,5 @@
// @flow
import { SHOW_ADS, DOMAIN, SIMPLE_SITE } from 'config';
import { DOMAIN, SIMPLE_SITE } from 'config';
import * as ICONS from 'constants/icons';
import * as PAGES from 'constants/pages';
import * as CS from 'constants/claim_search';
@ -31,7 +31,6 @@ type Props = {
tileLayout: boolean,
activeLivestreams: ?LivestreamInfo,
doFetchActiveLivestreams: (orderBy: ?Array<string>, lang: ?Array<string>) => void,
userHasPremiumPlus: boolean,
};
function DiscoverPage(props: Props) {
@ -48,7 +47,6 @@ function DiscoverPage(props: Props) {
activeLivestreams,
doFetchActiveLivestreams,
dynamicRouteProps,
userHasPremiumPlus,
} = props;
const buttonRef = useRef();
@ -190,9 +188,7 @@ function DiscoverPage(props: Props) {
tags={tags}
hiddenNsfwMessage={<HiddenNsfw type="page" />}
repostedClaimId={repostedClaim ? repostedClaim.claim_id : null}
injectedItem={
SHOW_ADS && !userHasPremiumPlus && !isWildWest && { node: <Ads small type="video" tileLayout={tileLayout} /> }
}
injectedItem={!isWildWest && { node: <Ads small type="video" tileLayout={tileLayout} /> }}
// Assume wild west page if no dynamicRouteProps
// Not a very good solution, but just doing it for now
// until we are sure this page will stay around

View file

@ -3,7 +3,7 @@ import * as SETTINGS from 'constants/settings';
import { doFetchActiveLivestreams } from 'redux/actions/livestream';
import { selectActiveLivestreams, selectFetchingActiveLivestreams } from 'redux/selectors/livestream';
import { selectFollowedTags } from 'redux/selectors/tags';
import { selectUserVerifiedEmail, selectOdyseeMembershipIsPremiumPlus } from 'redux/selectors/user';
import { selectUserVerifiedEmail } from 'redux/selectors/user';
import { selectSubscriptions } from 'redux/selectors/subscriptions';
import { selectShowMatureContent, selectHomepageData, selectClientSetting } from 'redux/selectors/settings';
@ -18,7 +18,6 @@ const select = (state) => ({
activeLivestreams: selectActiveLivestreams(state),
fetchingActiveLivestreams: selectFetchingActiveLivestreams(state),
hideScheduledLivestreams: selectClientSetting(state, SETTINGS.HIDE_SCHEDULED_LIVESTREAMS),
userHasPremiumPlus: selectOdyseeMembershipIsPremiumPlus(state),
});
const perform = (dispatch) => ({

View file

@ -1,7 +1,7 @@
// @flow
import * as ICONS from 'constants/icons';
import * as PAGES from 'constants/pages';
import { SHOW_ADS, SITE_NAME, SIMPLE_SITE, ENABLE_NO_SOURCE_CLAIMS } from 'config';
import { SITE_NAME, SIMPLE_SITE, ENABLE_NO_SOURCE_CLAIMS } from 'config';
import React, { useState } from 'react';
import Page from 'component/page';
import Button from 'component/button';
@ -31,7 +31,6 @@ type Props = {
doFetchActiveLivestreams: () => void,
fetchingActiveLivestreams: boolean,
hideScheduledLivestreams: boolean,
userHasPremiumPlus: boolean,
};
function HomePage(props: Props) {
@ -45,7 +44,6 @@ function HomePage(props: Props) {
doFetchActiveLivestreams,
fetchingActiveLivestreams,
hideScheduledLivestreams,
userHasPremiumPlus,
} = props;
const showPersonalizedChannels = (authenticated || !IS_WEB) && subscribedChannels && subscribedChannels.length > 0;
const showPersonalizedTags = (authenticated || !IS_WEB) && followedTags && followedTags.length > 0;
@ -101,11 +99,7 @@ function HomePage(props: Props) {
hasSource
prefixUris={getLivestreamUris(activeLivestreams, options.channelIds)}
pinUrls={pinUrls}
injectedItem={
index === 0 &&
SHOW_ADS &&
!userHasPremiumPlus && { node: <Ads small type="video" tileLayout />, replace: true }
}
injectedItem={index === 0 && { node: <Ads small type="video" tileLayout />, replace: true }}
/>
);

View file

@ -8,7 +8,6 @@ import {
makeSelectHasReachedMaxResultsLength,
} from 'redux/selectors/search';
import { selectShowMatureContent } from 'redux/selectors/settings';
import { selectUserVerifiedEmail } from 'redux/selectors/user';
import { getSearchQueryString } from 'util/query-params';
import SearchPage from './view';
@ -36,7 +35,6 @@ const select = (state, props) => {
searchOptions,
isSearching: selectIsSearching(state),
uris: uris,
isAuthenticated: selectUserVerifiedEmail(state),
hasReachedMaxResultsLength: hasReachedMaxResultsLength,
};
};

View file

@ -1,5 +1,5 @@
// @flow
import { SIMPLE_SITE, SHOW_ADS } from 'config';
import { SIMPLE_SITE } from 'config';
import React, { useEffect } from 'react';
import Lbry from 'lbry';
import { parseURI, isNameValid } from 'util/lbryURI';
@ -23,7 +23,7 @@ type Props = {
};
export default function SearchPage(props: Props) {
const { urlQuery, searchOptions, search, uris, isSearching, isAuthenticated, hasReachedMaxResultsLength } = props;
const { urlQuery, searchOptions, search, uris, isSearching, hasReachedMaxResultsLength } = props;
const { push } = useHistory();
const [from, setFrom] = React.useState(0);
@ -103,13 +103,7 @@ export default function SearchPage(props: Props) {
onSearchOptionsChanged={resetPage}
/>
}
injectedItem={
SHOW_ADS &&
!isAuthenticated && {
node: <Ads small type="video" />,
index: 3,
}
}
injectedItem={{ node: <Ads small type="video" />, index: 3 }}
/>
<div className="main--empty help">{__('These search results are provided by Odysee.')}</div>