Skip to content

Commit

Permalink
Fix: keyboard clicks on gaps. also es6ify
Browse files Browse the repository at this point in the history
  • Loading branch information
samouri committed Mar 28, 2017
1 parent cd6589a commit da02249
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 29 deletions.
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

0 comments on commit da02249

Please sign in to comment.