Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reader: connect new combined cards component to streams #11875

Merged
merged 17 commits into from
Mar 9, 2017

Conversation

samouri
Copy link
Contributor

@samouri samouri commented Mar 8, 2017

This PR adds the new ReaderCombinedCard component (#11407) to streams.

It will bundle up consecutive posts from the same feed or site into one combined card rather than many individual post cards.

c3f31c9c-f390-11e6-9fc2-a7a9ba6bd9db

samouri added 2 commits March 7, 2017 20:47
Have you ever been frustrated about specific RSS feeds overcrowding your Reader streams?
Well if so, this here commit is one you will love! It lumps same-site cards together to save you some valuable screen real estate!
@samouri samouri self-assigned this Mar 8, 2017
@samouri samouri requested a review from fraying March 8, 2017 02:03
@matticbot
Copy link
Contributor

@matticbot matticbot added the [Size] L Large sized issue label Mar 8, 2017
@bluefuton bluefuton changed the title Reader: connecting combined cards Reader: connect new combined cards component to streams Mar 8, 2017
@bluefuton bluefuton added the [Feature] Reader The reader site on Calypso. label Mar 8, 2017
/**
* Returns true if two postKeys are for the same siteId or feedId.
*
* @param {*} postKey1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

{*} - should always be an object right?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated 👍

*
* @param {*} postKey1
* @param {*} postKey2
*/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a @returns too?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added 👍

}
}

const combineCards = ( postKeys ) => postKeys.reduce(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a comment explaining what this does?

const combineCards = ( postKeys ) => postKeys.reduce(
( accumulator, postKey ) => {
const lastPostKey = last( accumulator );
if ( sameSite( lastPostKey, postKey ) && ( ! lastPostKey.postIds || lastPostKey.postIds.length < 5 ) ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we extract 5 to a const? Not clear what the limit is for.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think it was just an arbitrary limit to limit the size of a combined block

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 I've moved it to MAX_COMBINED_CARD_POSTS.

@matticbot matticbot added the [Size] L Large sized issue label Mar 8, 2017
@bluefuton
Copy link
Contributor

Looks like it can go a bit pear-shaped when new posts arrive (clicked on the "1 new post" pill):

screen shot 2017-03-08 at 14 36 52

@bluefuton
Copy link
Contributor

We also need to hand the combined card a site and feed (we've done this with ConnectedReaderPostCardAdapter and ReaderPostCardAdapterFluxContainer for regular posts).

postKey={ postKey }
index={ index }
key={ `combined-card-${ index }` }
onClick={ post => showSelectedPost( {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't want this to be an anonymous function. it'll cause the combo card to re-render every time we do a render pass, even if nothing changed.

@matticbot matticbot added [Size] XL Probably needs to be broken down into multiple smaller issues and removed [Size] L Large sized issue labels Mar 8, 2017
@@ -211,7 +211,10 @@ class ReaderStream extends React.Component {
}

if ( config.isEnabled( 'reader/combined-cards' ) ) {
items = combineCards( items );
// Create combined cards unless we're on a site or feed stream
if ( ! startsWith( store.id, 'feed:' ) && ! startsWith( store.id, 'site:' ) ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe pass this in as a prop to the stream?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about that - but what's the best format to do that (capturing the startsWith malarkey too)? A regex?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see now. We want a showCombinedCards prop or similar on the stream component itself.

const combineCards = ( postKeys ) => postKeys.reduce(
( accumulator, postKey ) => {
const lastPostKey = last( accumulator );
if ( sameSite( lastPostKey, postKey ) && ( ! lastPostKey.postIds || lastPostKey.postIds.length < MAX_COMBINED_CARD_POSTS ) ) {
Copy link
Contributor Author

@samouri samouri Mar 8, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we aren't including this on site-stream/feed-stream we can nix the: ( ! lastPostKey.postIds || lastPostKey.postIds.length < MAX_COMBINED_CARD_POSTS )

@@ -150,6 +209,14 @@ class ReaderStream extends React.Component {
if ( ! this.state || posts !== this.state.posts || recs !== this.state.recs ) {
items = injectRecommendations( posts, recs );
}

if ( config.isEnabled( 'reader/combined-cards' ) ) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice work @bluefuton!

@matticbot matticbot added the [Size] XL Probably needs to be broken down into multiple smaller issues label Mar 8, 2017
@samouri samouri added [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. and removed [Status] In Progress labels Mar 8, 2017
@@ -438,6 +503,22 @@ class ReaderStream extends React.Component {
/>;
}

if ( postKey.isCombination ) {
const handleClick = post => showSelectedPost( {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this has the same problem as before :D you're making a new function for every combined card every time render runs. That means the combined card is getting different props and cannot take advantage of shouldComponentUpdate to avoid re-rendering.

Copy link
Contributor Author

@samouri samouri Mar 8, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@blowery, lets handle that in a separate PR and keep this focused on the new component

@matticbot matticbot added the [Size] XL Probably needs to be broken down into multiple smaller issues label Mar 8, 2017
Copy link
Contributor

@fraying fraying left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lookin good! Posted design tweaks to #11913.

@fraying
Copy link
Contributor

fraying commented Mar 9, 2017

Bug Note: Combined Cards currently break keyboard navigation. Active card moves down ("j") until you hit a CC then it just goes away. If you keep hitting "j" the last post before the CC selects and deselects.

@matticbot matticbot added the [Size] XL Probably needs to be broken down into multiple smaller issues label Mar 9, 2017
@@ -121,7 +121,7 @@
"press-this": true,
"push-notifications": true,
"reader": true,
"reader/combined-cards": true,
"reader/combined-cards": false,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

@@ -22,7 +22,7 @@ class CrossPost extends PureComponent {
xMetadata: React.PropTypes.object.isRequired,
xPostedTo: React.PropTypes.array,
handleClick: React.PropTypes.func.isRequired,
translate: React.PropTypes.func.isRequried,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice find!

@bluefuton bluefuton merged commit ebed741 into master Mar 9, 2017
@bluefuton bluefuton deleted the add/reader/connect-combinedcards branch March 9, 2017 15:07
@matticbot matticbot removed the [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. label Mar 9, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Reader The reader site on Calypso. [Size] XL Probably needs to be broken down into multiple smaller issues
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants