Skip to content

Commit

Permalink
Merge pull request #245 from thematters/fix/comment-count
Browse files Browse the repository at this point in the history
fix comment count
  • Loading branch information
guoliu authored Apr 30, 2019
2 parents 351a7af + 071bc77 commit a63cdb8
Show file tree
Hide file tree
Showing 4 changed files with 555 additions and 547 deletions.
4 changes: 3 additions & 1 deletion common/utils/connections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ export const mergeConnections = ({
const { edges: newEdges, pageInfo: newPageInfo } = _get(newData, path)

const result = oldData

if (newPageInfo.endCursor !== oldPageInfo.endCursor) {
_set(result, path, {
const copy = JSON.parse(JSON.stringify(result))
return _set(copy, path, {
...rest,
pageInfo: newPageInfo,
edges: [...oldEdges, ...newEdges]
Expand Down
19 changes: 13 additions & 6 deletions components/ArticleDigest/Actions/CommentCount.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ import Link from 'next/link'

import { Icon, TextIcon } from '~/components'

import { numAbbr, toPath } from '~/common/utils'
import { ANALYTICS_EVENTS } from '~/common/enums'
import { analytics, numAbbr, toPath } from '~/common/utils'
import ICON_COMMENT_SM from '~/static/icons/comment-small.svg?sprite'

import { CommentCountArticle } from './__generated__/CommentCountArticle'

const fragments = {
article: gql`
fragment CommentCountArticle on Article {
id
slug
mediaHash
comments(input: { first: 0 }) {
totalCount
}
commentCount
author {
userName
}
Expand Down Expand Up @@ -47,7 +47,14 @@ const CommentCount = ({

return (
<Link {...path}>
<a>
<a
onClick={() => {
analytics.trackEvent(ANALYTICS_EVENTS.OPEN_COMMENTS, {
entrance: article.id,
type: 'article-digest'
})
}}
>
<TextIcon
icon={
<Icon
Expand All @@ -58,7 +65,7 @@ const CommentCount = ({
}
color="grey"
weight="medium"
text={numAbbr(_get(article, 'comments.totalCount', 0))}
text={numAbbr(_get(article, 'commentCount', 0))}
size={size === 'default' ? 'sm' : 'xs'}
spacing="xxtight"
/>
Expand Down
Loading

0 comments on commit a63cdb8

Please sign in to comment.