Skip to content

Instantly share code, notes, and snippets.

@itsjoekent
Created September 15, 2017 17:16
Show Gist options
  • Save itsjoekent/c87e3cbf2d355ace02ac0f3273bbaf07 to your computer and use it in GitHub Desktop.
Save itsjoekent/c87e3cbf2d355ace02ac0f3273bbaf07 to your computer and use it in GitHub Desktop.
/*
* view the diff here https://imgur.com/a/cdHwP
*/
import { connect } from 'react-redux';
import { Connector as PuckConnector } from 'puck-client';
import Feed from './Feed';
import { clickedViewMore, clickedSignUp } from '../../actions';
import {
getBlocksWithReportbacks,
getVisibleBlocks,
getBlockOffset,
getMaximumOffset,
} from '../../selectors/feed';
/**
* Provide state from the Redux store as props for this component.
*/
const mapStateToProps = state => ({
blocks: getBlocksWithReportbacks(getVisibleBlocks(state), state),
canLoadMorePages: getBlockOffset(state) < getMaximumOffset(state),
campaignId: state.campaign.legacyCampaignId,
callToAction: state.campaign.callToAction,
signedUp: state.signups.data.includes(state.campaign.legacyCampaignId),
hasNewSignup: state.signups.thisSession,
hasPendingSignup: state.signups.isPending,
isAuthenticated: state.user.id !== null,
});
/**
* Provide pre-bound functions that allow the component to dispatch
* actions to the Redux store as props for this component.
*/
const actionCreators = {
clickedViewMore,
clickedSignUp,
};
const mapPropsToEvents = (trackEvent) => ({
clickedViewMore: props => (
trackEvent('feed clicked view more', { campaignId: props.campaignId })
),
});
// Export the container component.
export default connect(mapStateToProps, actionCreators)(PuckConnector(Feed, mapPropsToEvents));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment