@@ -4,6 +4,7 @@ import { useSheetContext } from "@follow/components/ui/sheet/context.js"
44import type { FeedViewType } from "@follow/constants"
55import { tracker } from "@follow/tracker"
66import { useCallback } from "react"
7+ import { toast } from "sonner"
78
89import { disableShowAISummaryOnce } from "~/atoms/ai-summary"
910import { 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
104145export const useBackHome = ( timelineId ?: string ) => {
0 commit comments