Skip to content

Commit

Permalink
Odyssey: Fix post like counts (#95141)
Browse files Browse the repository at this point in the history
  • Loading branch information
kangzj authored Oct 4, 2024
1 parent db4cead commit cb30bbf
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions client/my-sites/stats/stats-post-detail/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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,
};
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit cb30bbf

Please sign in to comment.