Skip to content

Commit

Permalink
Merge pull request #4771 from thematters/fix/moment-like-visitor
Browse files Browse the repository at this point in the history
fix(MomentDigest): fix visitor mode
  • Loading branch information
wlliaml authored Aug 23, 2024
2 parents 514545c + 02d2adb commit ff0183b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/common/enums/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export enum UNIVERSAL_AUTH_TRIGGER {
support = 'support',
visitorWall = 'visitorWall',
momentComment = 'momentComment',
momentLike = 'momentLike',
}

/**
Expand Down
17 changes: 15 additions & 2 deletions src/components/MomentDigest/FooterActions/LikeButton/index.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import classNames from 'classnames'
import gql from 'graphql-tag'
import { useState } from 'react'
import { useContext, useState } from 'react'
import { useIntl } from 'react-intl'

import { ReactComponent as IconLike } from '@/public/static/icons/24px/like.svg'
import { ReactComponent as IconLikeFill } from '@/public/static/icons/24px/like-fill.svg'
import {
OPEN_UNIVERSAL_AUTH_DIALOG,
UNIVERSAL_AUTH_TRIGGER,
} from '~/common/enums'
import { numAbbr } from '~/common/utils'
import { Button, useMutation } from '~/components'
import { Button, useMutation, ViewerContext } from '~/components'
import {
LIKE_MOMENT,
UNLIKE_MOMENT,
Expand Down Expand Up @@ -47,6 +51,7 @@ const fragments = {

const LikeButton = ({ moment, iconSize = 20 }: LikeButtonProps) => {
const intl = useIntl()
const viewer = useContext(ViewerContext)
const { likeCount, liked } = moment

const [playHeartBeat, setPlayHeartBeat] = useState(false)
Expand Down Expand Up @@ -114,6 +119,14 @@ const LikeButton = ({ moment, iconSize = 20 }: LikeButtonProps) => {
textColor="black"
textActiveColor="greyDarker"
onClick={() => {
if (!viewer.isAuthed) {
window.dispatchEvent(
new CustomEvent(OPEN_UNIVERSAL_AUTH_DIALOG, {
detail: { trigger: UNIVERSAL_AUTH_TRIGGER.momentLike },
})
)
return
}
likeMoment()
setPlayHeartBeat(true)
}}
Expand Down

0 comments on commit ff0183b

Please sign in to comment.