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

Fix: keyboard clicks on gaps. also es6ify #12604

Merged
merged 1 commit into from
Mar 29, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 19 additions & 26 deletions client/reader/list-gap/index.jsx
Original file line number Diff line number Diff line change
@@ -1,51 +1,44 @@
/**
* External Dependencies
*/
var React = require( 'react' ),
classnames = require( 'classnames' );
import React from 'react';
import classnames from 'classnames';
import { localize } from 'i18n-calypso';

/**
* Internal Dependencies
*/
var FeedStreamStoreActions = require( 'lib/feed-stream-store/actions' ),
stats = require( 'reader/stats' );
import { handleGapClicked } from 'reader/utils';

var Gap = React.createClass( {
class Gap extends React.Component {

propTypes: {
static propTypes = {
gap: React.PropTypes.object.isRequired,
store: React.PropTypes.object.isRequired,
selected: React.PropTypes.bool
},
};

getInitialState: function() {
return { isFilling: false };
},
state = { isFilling: false };

render: function() {
var classes = classnames( {
handleClick = () => {
this.setState( { isFilling: true } );
handleGapClicked( this.props.gap, this.props.store.id );
}

render() {
const classes = classnames( {
'reader-list-gap': true,
'is-filling': this.state.isFilling,
'is-selected': this.props.selected
} );
const { translate } = this.props;

return (
<div className={ classes } onClick={ this.handleClick } >
<button type="button" className="button reader-list-gap__button">{ this.translate( 'Load More Posts' ) }</button>
<button type="button" className="button reader-list-gap__button">{ translate( 'Load More Posts' ) }</button>
</div>
);
},

handleClick: function() {
FeedStreamStoreActions.fillGap( this.props.store.id, this.props.gap );
this.setState( { isFilling: true } );
stats.recordAction( 'fill_gap' );
stats.recordGaEvent( 'Clicked Fill Gap' );
stats.recordTrack( 'calypso_reader_filled_gap', {
stream: this.props.store.id
} );
}
}

} );

module.exports = Gap;
export default localize( Gap );
1 change: 0 additions & 1 deletion client/reader/stream/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,6 @@ class ReaderStream extends React.Component {
const selectedPostKey = this.props.postsStore.getSelectedPostKey();
showSelectedPost( {
store: this.props.postsStore,
selectedGap: selectedPostKey.isGap && selectedPostKey,
postKey: selectedPostKey,
} );
}
Expand Down
17 changes: 15 additions & 2 deletions client/reader/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import FeedDisplayHelper from 'reader/lib/feed-display-helper';
import PostStore from 'lib/feed-post-store';
import XPostHelper, { isXPost } from 'reader/xpost-helper';
import { setLastStoreId } from 'reader/controller-helper';
import { fillGap } from 'lib/feed-stream-store/actions';
import { recordAction, recordGaEvent, recordTrack } from 'reader/stats';

export function siteNameFromSiteAndPost( site, post ) {
let siteName;
Expand Down Expand Up @@ -75,15 +77,15 @@ export function isPostNotFound( post ) {
return post.statusCode === 404;
}

export function showSelectedPost( { store, replaceHistory, selectedGap, postKey, comments } ) {
export function showSelectedPost( { store, replaceHistory, postKey, comments } ) {
if ( ! postKey ) {
return;
}

setLastStoreId( store && store.id );

if ( postKey.isGap === true ) {
return selectedGap.handleClick();
return handleGapClicked( postKey, store.id );
}

// rec block
Expand Down Expand Up @@ -133,6 +135,17 @@ export function showFullXPost( xMetadata ) {
}
}

export function handleGapClicked( postKey, storeId ) {
if ( ! postKey || ! postKey.isGap || ! storeId ) {
return;
}

fillGap( storeId, postKey );
recordAction( 'fill_gap' );
recordGaEvent( 'Clicked Fill Gap' );
recordTrack( 'calypso_reader_filled_gap', { stream: storeId } );
}

export function showFullPost( { post, replaceHistory, comments } ) {
const hashtag = comments ? '#comments' : '';
let query = '';
Expand Down