Skip to content

Commit be7e5cc

Browse files
authored
Reader: Show login prompts on all logged out reader streams
In #101923 we have added the functionality to show Login Prompt on selected reader streams, now we are updating this logic to show the login prompt on all reader streams which includes. - /discover - /search - /tag/:tag_name - All future pages that uses ReaderStream component
1 parent 2271c83 commit be7e5cc

File tree

6 files changed

+22
-27
lines changed

6 files changed

+22
-27
lines changed

client/reader/discover/discover-stream.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ const DiscoverStream = ( props ) => {
105105
showBack: false, // We will instead add this through the header section, since not all discover tabs have a stream to render the back button.
106106
sidebarTabTitle: isDefaultTab ? translate( 'Sites' ) : translate( 'Related' ),
107107
selectedStreamName: selectedTab,
108-
disableInfiniteScroll: ! isLoggedIn,
109108
};
110109

111110
const HeaderAndNavigation = () => {

client/reader/reader.const.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const MAX_POSTS_FOR_LOGGED_OUT_USERS: number = 10;

client/reader/search-stream/index.jsx

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,6 @@ class SearchStream extends React.Component {
4949
static propTypes = {
5050
query: PropTypes.string,
5151
streamKey: PropTypes.string,
52-
disableInfiniteScroll: PropTypes.bool,
53-
};
54-
55-
static defaultProps = {
56-
disableInfiniteScroll: false,
5752
};
5853

5954
state = {
@@ -241,7 +236,6 @@ class SearchStream extends React.Component {
241236
query={ query }
242237
sort={ pickSort( sortOrder ) }
243238
onReceiveSearchResults={ this.setSearchFeeds }
244-
disableInfiniteScroll={ this.props.disableInfiniteScroll }
245239
/>
246240
) }
247241
{ ! query && (
@@ -263,7 +257,6 @@ class SearchStream extends React.Component {
263257
query={ query }
264258
sort={ pickSort( sortOrder ) }
265259
onReceiveSearchResults={ this.setSearchFeeds }
266-
disableInfiniteScroll={ this.props.disableInfiniteScroll }
267260
/>
268261
) ) || (
269262
<ReaderPopularSitesSidebar

client/reader/search-stream/site-results.jsx

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import withDimensions from 'calypso/lib/with-dimensions';
77
import ReaderInfiniteStream from 'calypso/reader/components/reader-infinite-stream';
88
import { siteRowRenderer } from 'calypso/reader/components/reader-infinite-stream/row-renderers';
99
import { SEARCH_RESULTS_SITES } from 'calypso/reader/follow-sources';
10+
import { MAX_POSTS_FOR_LOGGED_OUT_USERS } from 'calypso/reader/reader.const';
11+
import { isUserLoggedIn } from 'calypso/state/current-user/selectors';
1012
import {
1113
requestFeedSearch,
1214
SORT_BY_RELEVANCE,
@@ -18,8 +20,6 @@ import {
1820
} from 'calypso/state/reader/feed-searches/selectors';
1921
import { getFeed } from 'calypso/state/reader/feeds/selectors';
2022

21-
const MIN_DESIRED_SITE_RESULTS = 10;
22-
2323
class SiteResults extends Component {
2424
static propTypes = {
2525
query: PropTypes.string,
@@ -29,15 +29,10 @@ class SiteResults extends Component {
2929
searchResults: PropTypes.array,
3030
searchResultsCount: PropTypes.number,
3131
width: PropTypes.number.isRequired,
32-
disableInfiniteScroll: PropTypes.bool,
33-
};
34-
35-
static defaultProps = {
36-
disableInfiniteScroll: false,
3732
};
3833

3934
fetchNextPage = ( offset ) => {
40-
if ( this.props.disableInfiniteScroll && offset > MIN_DESIRED_SITE_RESULTS ) {
35+
if ( this.isLoginPromptVisible( offset ) ) {
4136
return;
4237
}
4338

@@ -50,12 +45,17 @@ class SiteResults extends Component {
5045
};
5146

5247
hasNextPage = ( offset ) => {
53-
if ( this.props.disableInfiniteScroll && offset > MIN_DESIRED_SITE_RESULTS ) {
48+
if ( this.isLoginPromptVisible( offset ) ) {
5449
return false;
5550
}
5651
return offset < this.props.searchResultsCount;
5752
};
5853

54+
isLoginPromptVisible( offset ) {
55+
// Show login prompt for all logged out users after few posts.
56+
return ! this.props.isLoggedIn && offset > MAX_POSTS_FOR_LOGGED_OUT_USERS;
57+
}
58+
5959
render() {
6060
const { query, searchResults, width, sort } = this.props;
6161
const isEmpty = query?.length > 0 && searchResults?.length === 0;
@@ -136,6 +136,7 @@ export default connect(
136136
ownProps.onReceiveSearchResults( feedResults );
137137
}
138138
return {
139+
isLoggedIn: isUserLoggedIn( state ),
139140
searchResults: searchResults,
140141
searchResultsCount: getReaderFeedsCountForQuery( state, {
141142
query: ownProps.query,

client/reader/search/controller.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ const exported = {
8888
onSortChange={ reportSortChange }
8989
searchType={ show }
9090
trendingTags={ context.params.trendingTags }
91-
disableInfiniteScroll={ ! context.store.getState().currentUser.user }
9291
/>
9392
</div>
9493
</div>

client/reader/stream/index.jsx

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import './style.scss';
12
import { isDefaultLocale } from '@automattic/i18n-utils';
23
import clsx from 'clsx';
34
import { localize } from 'i18n-calypso';
@@ -21,6 +22,7 @@ import { isEditorIframeFocused } from 'calypso/reader/components/quick-post/util
2122
import ReaderMain from 'calypso/reader/components/reader-main';
2223
import { shouldShowLikes } from 'calypso/reader/like-helper';
2324
import { keysAreEqual, keyToString } from 'calypso/reader/post-key';
25+
import { MAX_POSTS_FOR_LOGGED_OUT_USERS } from 'calypso/reader/reader.const';
2426
import ReaderStreamLoginPrompt from 'calypso/reader/stream/login-prompt';
2527
import UpdateNotice from 'calypso/reader/update-notice';
2628
import { showSelectedPost, getStreamType } from 'calypso/reader/utils';
@@ -56,7 +58,6 @@ import { CustomerCouncilBanner } from './customer-council-banner';
5658
import EmptyContent from './empty';
5759
import PostLifecycle from './post-lifecycle';
5860
import PostPlaceholder from './post-placeholder';
59-
import './style.scss';
6061

6162
// minimal size for the two-column layout to show without cut off
6263
// 64 is padding, 8 is margin
@@ -91,7 +92,6 @@ class ReaderStream extends Component {
9192
useCompactCards: PropTypes.bool,
9293
fixedHeaderHeight: PropTypes.number,
9394
selectedStreamName: PropTypes.string,
94-
disableInfiniteScroll: PropTypes.bool,
9595
isLoggedIn: PropTypes.bool,
9696
};
9797

@@ -108,7 +108,6 @@ class ReaderStream extends Component {
108108
showBack: true,
109109
suppressSiteNameLink: false,
110110
useCompactCards: false,
111-
disableInfiniteScroll: false,
112111
isLoggedIn: false,
113112
};
114113

@@ -488,7 +487,7 @@ class ReaderStream extends Component {
488487
};
489488

490489
fetchNextPage = ( options, props = this.props ) => {
491-
if ( this.props.disableInfiniteScroll && this.props.items.length > 10 ) {
490+
if ( this.isLoginPromptVisible() ) {
492491
return;
493492
}
494493

@@ -503,6 +502,11 @@ class ReaderStream extends Component {
503502
props.requestPage( { feedId: selectedFeedId, streamKey, pageHandle, localeSlug } );
504503
};
505504

505+
isLoginPromptVisible = () => {
506+
// Show login prompt for all logged out users after few posts.
507+
return ! this.props.isLoggedIn && this.props.items.length > MAX_POSTS_FOR_LOGGED_OUT_USERS;
508+
};
509+
506510
showUpdates = () => {
507511
const { streamKey } = this.props;
508512
this.props.onUpdatesShown();
@@ -755,11 +759,9 @@ class ReaderStream extends Component {
755759
{ showingStream && items.length ? this.props.intro?.() : null }
756760
{ body }
757761
{ showingStream && items.length && ! isRequesting ? <ListEnd /> : null }
758-
{ this.props.disableInfiniteScroll &&
759-
! this.props.isLoggedIn &&
760-
this.props.items.length > 0 && (
761-
<ReaderStreamLoginPrompt redirectPath={ window.location.pathname } />
762-
) }
762+
{ this.isLoginPromptVisible() && (
763+
<ReaderStreamLoginPrompt redirectPath={ window.location.pathname } />
764+
) }
763765
</TopLevel>
764766
);
765767
}

0 commit comments

Comments
 (0)