Skip to content

Commit d6d9044

Browse files
authored
fix: try fix can not navigation inbox item in prod
fix: try fix can not navigation inbox item in prod
2 parents 321ffc4 + c7b7b71 commit d6d9044

File tree

2 files changed

+75
-23
lines changed

2 files changed

+75
-23
lines changed

apps/desktop/layer/renderer/src/hooks/biz/useNavigateEntry.ts

Lines changed: 58 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { useSheetContext } from "@follow/components/ui/sheet/context.js"
44
import type { FeedViewType } from "@follow/constants"
55
import { tracker } from "@follow/tracker"
66
import { useCallback } from "react"
7+
import { toast } from "sonner"
78

89
import { disableShowAISummaryOnce } from "~/atoms/ai-summary"
910
import { disableShowAITranslationOnce } from "~/atoms/ai-translation"
@@ -46,14 +47,14 @@ export const useNavigateEntry = () => {
4647
)
4748
}
4849

49-
/*
50-
* /timeline/:timelineId/:feedId/:entryId
51-
* timelineId: view-1
52-
* feedId: xxx, folder-xxx, list-xxx, inbox-xxx
53-
* entryId: xxx
54-
*/
55-
export const navigateEntry = (options: NavigateEntryOptions) => {
56-
const { entryId, feedId, view, folderName, inboxId, listId, timelineId, backPath } = options || {}
50+
type ParsedNavigateEntryOptions = {
51+
feedId: string
52+
timelineId: string
53+
entryId: string
54+
}
55+
56+
const parseNavigateEntryOptions = (options: NavigateEntryOptions): ParsedNavigateEntryOptions => {
57+
const { entryId, feedId, view, folderName, inboxId, listId, timelineId } = options || {}
5758
const route = getReadonlyRoute()
5859
const { params } = route
5960
let finalFeedId = feedId || params.feedId || ROUTE_FEED_PENDING
@@ -62,10 +63,6 @@ export const navigateEntry = (options: NavigateEntryOptions) => {
6263
const subscription = getSubscriptionByFeedId(finalFeedId)
6364
const finalView = subscription?.view || view
6465

65-
if (backPath) {
66-
setPreviewBackPath(backPath)
67-
}
68-
6966
if ("feedId" in options && feedId === null) {
7067
finalFeedId = ROUTE_FEED_PENDING
7168
}
@@ -88,17 +85,61 @@ export const navigateEntry = (options: NavigateEntryOptions) => {
8885
finalTimelineId = `${ROUTE_TIMELINE_OF_VIEW}${finalView}`
8986
}
9087

88+
return {
89+
feedId: finalFeedId,
90+
timelineId: finalTimelineId,
91+
entryId: finalEntryId,
92+
}
93+
}
94+
95+
export function getNavigateEntryPath(options: NavigateEntryOptions | ParsedNavigateEntryOptions) {
96+
if ("feedId" in options) {
97+
return `/timeline/${options.timelineId}/${options.feedId}/${options.entryId}`
98+
}
99+
100+
const { feedId, timelineId, entryId } = parseNavigateEntryOptions(options)
101+
102+
return `/timeline/${timelineId}/${feedId}/${entryId}`
103+
}
104+
105+
/*
106+
* /timeline/:timelineId/:feedId/:entryId
107+
* timelineId: view-1
108+
* feedId: xxx, folder-xxx, list-xxx, inbox-xxx
109+
* entryId: xxx
110+
*/
111+
export const navigateEntry = (options: NavigateEntryOptions) => {
112+
const parsedOptions = parseNavigateEntryOptions(options)
113+
const path = getNavigateEntryPath(parsedOptions)
114+
const { backPath } = options || {}
115+
const route = getReadonlyRoute()
116+
const currentPath = route.location.pathname + route.location.search
117+
if (path === currentPath) return
118+
119+
if (backPath) {
120+
setPreviewBackPath(backPath)
121+
}
122+
123+
tracker.navigateEntry({
124+
feedId: parsedOptions.feedId,
125+
entryId: parsedOptions.entryId,
126+
timelineId: parsedOptions.timelineId,
127+
})
128+
91129
resetShowSourceContent()
92130
disableShowAISummaryOnce()
93131
disableShowAITranslationOnce()
94132

95-
tracker.navigateEntry({ feedId: finalFeedId, entryId: finalEntryId, timelineId: finalTimelineId })
133+
const navigate = getStableRouterNavigate()
96134

97-
const path = `/timeline/${finalTimelineId}/${finalFeedId}/${finalEntryId}`
135+
if (!navigate) {
136+
const message =
137+
"Navigation is not available, maybe a mistake in the code, please report an issue. thx."
138+
toast.error(message)
139+
throw new Error(message, { cause: "Navigation is not available" })
140+
}
98141

99-
const currentPath = route.location.pathname + route.location.search
100-
if (path === currentPath) return
101-
return getStableRouterNavigate()?.(path)
142+
return navigate?.(path)
102143
}
103144

104145
export const useBackHome = (timelineId?: string) => {

apps/desktop/layer/renderer/src/modules/entry-column/layouts/EntryItemWrapper.tsx

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ import { views } from "@follow/constants"
55
import { EventBus } from "@follow/utils/event-bus"
66
import { cn } from "@follow/utils/utils"
77
import type { FC, PropsWithChildren } from "react"
8-
import { useCallback, useState } from "react"
8+
import { useCallback, useMemo, useState } from "react"
99
import { useTranslation } from "react-i18next"
10+
import { NavLink } from "react-router"
1011
import { useDebounceCallback } from "usehooks-ts"
1112

1213
import {
@@ -21,7 +22,7 @@ import { useEntryIsRead } from "~/hooks/biz/useAsRead"
2122
import { useContextMenuActionShortCutTrigger } from "~/hooks/biz/useContextMenuActionShortCutTrigger"
2223
import { useEntryActions } from "~/hooks/biz/useEntryActions"
2324
import { useFeedActions } from "~/hooks/biz/useFeedActions"
24-
import { useNavigateEntry } from "~/hooks/biz/useNavigateEntry"
25+
import { getNavigateEntryPath, useNavigateEntry } from "~/hooks/biz/useNavigateEntry"
2526
import { getRouteParams, useRouteParamsSelector } from "~/hooks/biz/useRouteParams"
2627
import { useContextMenu } from "~/hooks/common/useContextMenu"
2728
import { COMMAND_ID } from "~/modules/command/commands/id"
@@ -74,11 +75,20 @@ export const EntryItemWrapper: FC<
7475
)
7576

7677
const navigate = useNavigateEntry()
78+
79+
const navigationPath = useMemo(() => {
80+
if (!entry?.id) return "#"
81+
return getNavigateEntryPath({
82+
entryId: entry?.id,
83+
})
84+
}, [entry?.id])
7785
const handleClick = useCallback(
7886
(e) => {
87+
e.preventDefault()
7988
e.stopPropagation()
8089

8190
const shouldNavigate = getRouteParams().entryId !== entry?.id
91+
8292
if (!shouldNavigate) return
8393
if (!entry?.feedId) return
8494
if (!asRead) {
@@ -96,7 +106,7 @@ export const EntryItemWrapper: FC<
96106
},
97107
[asRead, entry?.id, entry?.feedId, navigate],
98108
)
99-
const handleDoubleClick: React.MouseEventHandler<HTMLDivElement> = useCallback(
109+
const handleDoubleClick: React.MouseEventHandler<HTMLAnchorElement> = useCallback(
100110
() => entry?.url && window.open(entry.url, "_blank"),
101111
[entry?.url],
102112
)
@@ -168,9 +178,10 @@ export const EntryItemWrapper: FC<
168178

169179
return (
170180
<div data-entry-id={entry?.id} style={style}>
171-
<div
181+
<NavLink
182+
to={navigationPath}
172183
className={cn(
173-
"hover:bg-theme-item-hover relative duration-200",
184+
"hover:bg-theme-item-hover cursor-button relative block duration-200",
174185
views[view as FeedViewType]?.wideMode ? "rounded-md" : "px-2",
175186
(isActive || isContextMenuOpen) && "!bg-theme-item-active",
176187
itemClassName,
@@ -183,7 +194,7 @@ export const EntryItemWrapper: FC<
183194
{...(!isMobile ? { onTouchStart: handleClick } : {})}
184195
>
185196
{children}
186-
</div>
197+
</NavLink>
187198
</div>
188199
)
189200
}

0 commit comments

Comments
 (0)