diff --git a/client/blocks/reader-full-post/index.jsx b/client/blocks/reader-full-post/index.jsx index 51cc1f533a04e..63638a41a0e27 100644 --- a/client/blocks/reader-full-post/index.jsx +++ b/client/blocks/reader-full-post/index.jsx @@ -214,11 +214,7 @@ export class FullPostView extends Component { handleBack = ( event ) => { event.preventDefault(); - recordAction( 'full_post_close' ); - recordGaEvent( 'Closed Full Post Dialog' ); - recordTrackForPost( 'calypso_reader_article_closed', this.props.post ); - - this.props.onClose && this.props.onClose(); + this.props.onClose && this.props.onClose( this.props.post ); }; handleCommentClick = () => { diff --git a/client/reader/full-post/controller.js b/client/reader/full-post/controller.js index cd3419e5c7b60..a202ecdda85bc 100644 --- a/client/reader/full-post/controller.js +++ b/client/reader/full-post/controller.js @@ -2,6 +2,7 @@ import page from '@automattic/calypso-router'; import { defer } from 'lodash'; import AsyncLoad from 'calypso/components/async-load'; import { trackPageLoad } from 'calypso/reader/controller-helper'; +import { recordAction, recordGaEvent, recordTrackForPost } from 'calypso/reader/stats'; import { isUserLoggedIn } from 'calypso/state/current-user/selectors'; const analyticsPageTitle = 'Reader'; @@ -27,7 +28,11 @@ export function blogPost( context, next ) { trackPageLoad( basePath, fullPageTitle, 'full_post' ); const lastRoute = context.lastRoute || '/'; - function closer() { + function closer( post ) { + recordAction( 'full_post_close' ); + recordGaEvent( 'Closed Full Post Dialog' ); + recordTrackForPost( 'calypso_reader_article_closed', post ); + page.back( lastRoute ); } @@ -50,6 +55,8 @@ export function blogPost( context, next ) { placeholder={ null } returnPath={ lastRoute } onClose={ closer } + postId={ postId } + blogId={ blogId } /> ); } @@ -67,7 +74,11 @@ export function feedPost( context, next ) { trackPageLoad( basePath, fullPageTitle, 'full_post' ); const lastRoute = context.lastRoute || '/'; - function closer() { + function closer( post ) { + recordAction( 'full_post_close' ); + recordGaEvent( 'Closed Full Post Dialog' ); + recordTrackForPost( 'calypso_reader_article_closed', post ); + page.back( lastRoute ); } @@ -89,6 +100,8 @@ export function feedPost( context, next ) { placeholder={ null } returnPath={ lastRoute } onClose={ closer } + postId={ postId } + feedId={ feedId } /> ); } diff --git a/client/reader/sidebar/index.jsx b/client/reader/sidebar/index.jsx index 48a61f000e081..e13700b641f6d 100644 --- a/client/reader/sidebar/index.jsx +++ b/client/reader/sidebar/index.jsx @@ -3,7 +3,7 @@ import page from '@automattic/calypso-router'; import { hasTranslation } from '@wordpress/i18n'; import closest from 'component-closest'; import i18n, { localize } from 'i18n-calypso'; -import { defer, startsWith } from 'lodash'; +import { defer, pickBy, startsWith } from 'lodash'; import { Component } from 'react'; import { connect } from 'react-redux'; import QueryReaderLists from 'calypso/components/data/query-reader-lists'; @@ -33,6 +33,7 @@ import { getShouldShowGlobalSidebar } from 'calypso/state/global-sidebar/selecto import { recordReaderTracksEvent } from 'calypso/state/reader/analytics/actions'; import { getSubscribedLists } from 'calypso/state/reader/lists/selectors'; import { getReaderOrganizations } from 'calypso/state/reader/organizations/selectors'; +import { getPostByKey } from 'calypso/state/reader/posts/selectors'; import { toggleReaderSidebarLists, toggleReaderSidebarTags, @@ -297,7 +298,7 @@ export class ReaderSidebar extends Component { requireBackLink: true, siteTitle: i18n.translate( 'Reader' ), backLinkHref: this.props.returnPath || '/sites', - onClose: this.props.onClose, + onClose: this.props.onClose && ( () => this.props.onClose( this.props.post ) ), }; return ( @@ -333,7 +334,7 @@ export class ReaderSidebar extends Component { export default withCurrentRoute( connect( - ( state, { currentSection } ) => { + ( state, { currentSection, postId, blogId, feedId } ) => { const sectionGroup = currentSection?.group ?? null; const sectionName = currentSection?.name ?? null; const siteId = getSelectedSiteId( state ); @@ -343,6 +344,9 @@ export default withCurrentRoute( sectionGroup, sectionName ); + const postKey = pickBy( { feedId: +feedId, blogId: +blogId, postId: +postId } ); + const post = getPostByKey( state, postKey ) || { _state: 'pending' }; + return { isListsOpen: isListsOpen( state ), isTagsOpen: isTagsOpen( state ), @@ -350,6 +354,7 @@ export default withCurrentRoute( teams: getReaderTeams( state ), organizations: getReaderOrganizations( state ), shouldShowGlobalSidebar, + post, }; }, {