Skip to content

Commit

Permalink
fix(Moment): update date time navigation issues
Browse files Browse the repository at this point in the history
ref:
PR-2408-2-56
  • Loading branch information
wlliaml committed Aug 22, 2024
1 parent 128abb7 commit dbcb876
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/common/enums/moment.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const MOMENT_DIGEST_REFERRER = 'momentDigestReferrer'
14 changes: 8 additions & 6 deletions src/components/Dialogs/MomentDetailDialog/Content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import {
DISABLE_SUSPEND_DISMISS_ON_ESC,
ENABLE_SUSPEND_DISMISS_ON_ESC,
} from '~/common/enums'
import { makeMentionElement, toPath } from '~/common/utils'
import { MOMENT_DIGEST_REFERRER } from '~/common/enums/moment'
import { makeMentionElement, sessionStorage, toPath } from '~/common/utils'
import {
MomentDigestDetail,
QueryError,
Expand Down Expand Up @@ -103,17 +104,18 @@ const MomentDetailDialogContent = ({
})

const closeDialog = () => {
const isFirstPageVisit = window.history.length <= 1
if (isInMomentDetailPage && isFirstPageVisit) {
const momentDigestReferrer = sessionStorage.get(MOMENT_DIGEST_REFERRER)
if (isInMomentDetailPage && momentDigestReferrer) {
window.history.back()
}

if (isInMomentDetailPage && !momentDigestReferrer) {
const userProfilePath = toPath({
page: 'userProfile',
userName: moment.author.userName || '',
})
router.push(userProfilePath.href)
}
if (isInMomentDetailPage && !isFirstPageVisit) {
window.history.back()
}
_closeDialog()
}

Expand Down
9 changes: 7 additions & 2 deletions src/components/MomentDigest/Feed/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { FormattedMessage } from 'react-intl'

import { ReactComponent as IconDot } from '@/public/static/icons/dot.svg'
import { TEST_ID } from '~/common/enums'
import { captureClicks, toPath } from '~/common/utils'
import { MOMENT_DIGEST_REFERRER } from '~/common/enums/moment'
import { captureClicks, sessionStorage, toPath } from '~/common/utils'
import {
DateTime,
Expandable,
Expand Down Expand Up @@ -47,6 +48,10 @@ export const MomentDigestFeed = ({
router.push(momentDetailPath.href)
}

const handleClickDateTime = () => {
sessionStorage.set(MOMENT_DIGEST_REFERRER, true)
}

const Container = ({
openMomentDetail,
hasAuthor,
Expand All @@ -73,7 +78,7 @@ export const MomentDigestFeed = ({
</section>
)}
<section>
<LinkWrapper {...momentDetailPath}>
<LinkWrapper {...momentDetailPath} onClick={handleClickDateTime}>
<DateTime date={createdAt} color="grey" />
</LinkWrapper>
</section>
Expand Down

0 comments on commit dbcb876

Please sign in to comment.