From dbcb87603edb19e4052a7acb96fcbb94597d2c59 Mon Sep 17 00:00:00 2001 From: bluecloud <96812901+pitb2022@users.noreply.github.com> Date: Thu, 22 Aug 2024 11:01:38 +0800 Subject: [PATCH] fix(Moment): update date time navigation issues ref: PR-2408-2-56 --- src/common/enums/moment.ts | 1 + .../Dialogs/MomentDetailDialog/Content.tsx | 14 ++++++++------ src/components/MomentDigest/Feed/index.tsx | 9 +++++++-- 3 files changed, 16 insertions(+), 8 deletions(-) create mode 100644 src/common/enums/moment.ts diff --git a/src/common/enums/moment.ts b/src/common/enums/moment.ts new file mode 100644 index 0000000000..9a9de21945 --- /dev/null +++ b/src/common/enums/moment.ts @@ -0,0 +1 @@ +export const MOMENT_DIGEST_REFERRER = 'momentDigestReferrer' diff --git a/src/components/Dialogs/MomentDetailDialog/Content.tsx b/src/components/Dialogs/MomentDetailDialog/Content.tsx index 0f89b8074b..f0970463f1 100644 --- a/src/components/Dialogs/MomentDetailDialog/Content.tsx +++ b/src/components/Dialogs/MomentDetailDialog/Content.tsx @@ -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, @@ -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() } diff --git a/src/components/MomentDigest/Feed/index.tsx b/src/components/MomentDigest/Feed/index.tsx index c77fc4aa14..ec347c6fb4 100644 --- a/src/components/MomentDigest/Feed/index.tsx +++ b/src/components/MomentDigest/Feed/index.tsx @@ -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, @@ -47,6 +48,10 @@ export const MomentDigestFeed = ({ router.push(momentDetailPath.href) } + const handleClickDateTime = () => { + sessionStorage.set(MOMENT_DIGEST_REFERRER, true) + } + const Container = ({ openMomentDetail, hasAuthor, @@ -73,7 +78,7 @@ export const MomentDigestFeed = ({ )}
- +