diff --git a/client/my-sites/stats/stats-post-detail/index.jsx b/client/my-sites/stats/stats-post-detail/index.jsx index 343c399d925fa..814b5ec94fa4d 100644 --- a/client/my-sites/stats/stats-post-detail/index.jsx +++ b/client/my-sites/stats/stats-post-detail/index.jsx @@ -16,6 +16,7 @@ import NavigationHeader from 'calypso/components/navigation-header'; import WebPreview from 'calypso/components/web-preview'; import { decodeEntities, stripHTML } from 'calypso/lib/formatting'; import { getSitePost, getPostPreviewUrl } from 'calypso/state/posts/selectors'; +import { countPostLikes } from 'calypso/state/posts/selectors/count-post-likes'; import { getSiteSlug, isJetpackSite, isSitePreviewable } from 'calypso/state/sites/selectors'; import getEnvStatsFeatureSupportChecks from 'calypso/state/sites/selectors/get-env-stats-feature-supports'; import { getPostStat, isRequestingPostStats } from 'calypso/state/stats/posts/selectors'; @@ -108,32 +109,31 @@ class StatsPostDetail extends Component { } getPost() { - const { isPostHomepage, post, postFallback } = this.props; + const { isPostHomepage, post, postFallback, countLikes } = this.props; const postBase = { title: this.getTitle(), type: isPostHomepage ? 'page' : 'post', + like_count: countLikes || 0, }; // Check if post is valid. - if ( typeof post === 'object' && post?.title.length ) { + if ( typeof post === 'object' && post?.title?.length ) { return { ...postBase, date: post?.date, post_thumbnail: post?.post_thumbnail, - like_count: post?.like_count, comment_count: post?.discussion?.comment_count, type: post?.type, }; } // Check if postFallback is valid. - if ( typeof postFallback === 'object' && postFallback?.post_title.length ) { + if ( typeof postFallback === 'object' && postFallback?.post_title?.length ) { return { ...postBase, date: postFallback?.post_date_gmt, post_thumbnail: null, - like_count: null, comment_count: parseInt( postFallback?.comment_count, 10 ), type: postFallback?.post_type, }; @@ -252,11 +252,12 @@ const connectComponent = connect( ( state, { postId } ) => { const isJetpack = isJetpackSite( state, siteId ); const isPreviewable = isSitePreviewable( state, siteId ); const isPostHomepage = postId === 0; - + const countLikes = countPostLikes( state, siteId, postId ) || 0; const { supportsUTMStats } = getEnvStatsFeatureSupportChecks( state, siteId ); return { post: getSitePost( state, siteId, postId ), + countLikes, // NOTE: Post object from the stats response does not conform to the data structure returned by getSitePost! postFallback: getPostStat( state, siteId, postId, 'post' ), isPostHomepage,