-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Conversation
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!
client/reader/stream/index.jsx
Outdated
/** | ||
* Returns true if two postKeys are for the same siteId or feedId. | ||
* | ||
* @param {*} postKey1 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated 👍
client/reader/stream/index.jsx
Outdated
* | ||
* @param {*} postKey1 | ||
* @param {*} postKey2 | ||
*/ |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added 👍
client/reader/stream/index.jsx
Outdated
} | ||
} | ||
|
||
const combineCards = ( postKeys ) => postKeys.reduce( |
There was a problem hiding this comment.
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?
client/reader/stream/index.jsx
Outdated
const combineCards = ( postKeys ) => postKeys.reduce( | ||
( accumulator, postKey ) => { | ||
const lastPostKey = last( accumulator ); | ||
if ( sameSite( lastPostKey, postKey ) && ( ! lastPostKey.postIds || lastPostKey.postIds.length < 5 ) ) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
.
We also need to hand the combined card a |
client/reader/stream/index.jsx
Outdated
postKey={ postKey } | ||
index={ index } | ||
key={ `combined-card-${ index }` } | ||
onClick={ post => showSelectedPost( { |
There was a problem hiding this comment.
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.
client/reader/stream/index.jsx
Outdated
@@ -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:' ) ) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
client/reader/stream/index.jsx
Outdated
const combineCards = ( postKeys ) => postKeys.reduce( | ||
( accumulator, postKey ) => { | ||
const lastPostKey = last( accumulator ); | ||
if ( sameSite( lastPostKey, postKey ) && ( ! lastPostKey.postIds || lastPostKey.postIds.length < MAX_COMBINED_CARD_POSTS ) ) { |
There was a problem hiding this comment.
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 )
client/reader/stream/index.jsx
Outdated
@@ -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' ) ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice work @bluefuton!
client/reader/stream/index.jsx
Outdated
@@ -438,6 +503,22 @@ class ReaderStream extends React.Component { | |||
/>; | |||
} | |||
|
|||
if ( postKey.isCombination ) { | |||
const handleClick = post => showSelectedPost( { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm afraid they all have this issue then: https://github.com/Automattic/wp-calypso/pull/11875/files/757a735aed29c4813ea40a346dd5a0f95e29dc93#diff-52f7f0c436e060a64c7081104b31880aR523.
could also be related to the rerender issue #11856
There was a problem hiding this comment.
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
There was a problem hiding this 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.
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. |
config/development.json
Outdated
@@ -121,7 +121,7 @@ | |||
"press-this": true, | |||
"push-notifications": true, | |||
"reader": true, | |||
"reader/combined-cards": true, | |||
"reader/combined-cards": false, |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice find!
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.