Merge pull request #3988 from RSSNext/sync/main-to-dev-20250623
Sync main branch to dev branch
This commit is contained in:
@@ -6,6 +6,7 @@ import { getSubscriptionByFeedId } from "@follow/store/subscription/getter"
|
||||
import { tracker } from "@follow/tracker"
|
||||
import { nextFrame } from "@follow/utils"
|
||||
import { useCallback } from "react"
|
||||
import { toast } from "sonner"
|
||||
|
||||
import { disableShowAISummaryOnce } from "~/atoms/ai-summary"
|
||||
import { disableShowAITranslationOnce } from "~/atoms/ai-translation"
|
||||
@@ -47,14 +48,14 @@ export const useNavigateEntry = () => {
|
||||
)
|
||||
}
|
||||
|
||||
/*
|
||||
* /timeline/:timelineId/:feedId/:entryId
|
||||
* timelineId: view-1
|
||||
* feedId: xxx, folder-xxx, list-xxx, inbox-xxx
|
||||
* entryId: xxx
|
||||
*/
|
||||
export const navigateEntry = (options: NavigateEntryOptions) => {
|
||||
const { entryId, feedId, view, folderName, inboxId, listId, timelineId, backPath } = options || {}
|
||||
type ParsedNavigateEntryOptions = {
|
||||
feedId: string
|
||||
timelineId: string
|
||||
entryId: string
|
||||
}
|
||||
|
||||
const parseNavigateEntryOptions = (options: NavigateEntryOptions): ParsedNavigateEntryOptions => {
|
||||
const { entryId, feedId, view, folderName, inboxId, listId, timelineId } = options || {}
|
||||
const route = getReadonlyRoute()
|
||||
const { params } = route
|
||||
let finalFeedId = feedId || params.feedId || ROUTE_FEED_PENDING
|
||||
@@ -63,10 +64,6 @@ export const navigateEntry = (options: NavigateEntryOptions) => {
|
||||
const subscription = getSubscriptionByFeedId(finalFeedId)
|
||||
const finalView = subscription?.view || view
|
||||
|
||||
if (backPath) {
|
||||
setPreviewBackPath(backPath)
|
||||
}
|
||||
|
||||
if ("feedId" in options && feedId === null) {
|
||||
finalFeedId = ROUTE_FEED_PENDING
|
||||
}
|
||||
@@ -89,6 +86,47 @@ export const navigateEntry = (options: NavigateEntryOptions) => {
|
||||
finalTimelineId = `${ROUTE_TIMELINE_OF_VIEW}${finalView}`
|
||||
}
|
||||
|
||||
return {
|
||||
feedId: finalFeedId,
|
||||
timelineId: finalTimelineId,
|
||||
entryId: finalEntryId,
|
||||
}
|
||||
}
|
||||
|
||||
export function getNavigateEntryPath(options: NavigateEntryOptions | ParsedNavigateEntryOptions) {
|
||||
if ("feedId" in options) {
|
||||
return `/timeline/${options.timelineId}/${options.feedId}/${options.entryId}`
|
||||
}
|
||||
|
||||
const { feedId, timelineId, entryId } = parseNavigateEntryOptions(options)
|
||||
|
||||
return `/timeline/${timelineId}/${feedId}/${entryId}`
|
||||
}
|
||||
|
||||
/*
|
||||
* /timeline/:timelineId/:feedId/:entryId
|
||||
* timelineId: view-1
|
||||
* feedId: xxx, folder-xxx, list-xxx, inbox-xxx
|
||||
* entryId: xxx
|
||||
*/
|
||||
export const navigateEntry = (options: NavigateEntryOptions) => {
|
||||
const parsedOptions = parseNavigateEntryOptions(options)
|
||||
const path = getNavigateEntryPath(parsedOptions)
|
||||
const { backPath } = options || {}
|
||||
const route = getReadonlyRoute()
|
||||
const currentPath = route.location.pathname + route.location.search
|
||||
if (path === currentPath) return
|
||||
|
||||
if (backPath) {
|
||||
setPreviewBackPath(backPath)
|
||||
}
|
||||
|
||||
tracker.navigateEntry({
|
||||
feedId: parsedOptions.feedId,
|
||||
entryId: parsedOptions.entryId,
|
||||
timelineId: parsedOptions.timelineId,
|
||||
})
|
||||
|
||||
disableShowAISummaryOnce()
|
||||
disableShowAITranslationOnce()
|
||||
|
||||
@@ -96,13 +134,16 @@ export const navigateEntry = (options: NavigateEntryOptions) => {
|
||||
resetShowSourceContent()
|
||||
})
|
||||
|
||||
tracker.navigateEntry({ feedId: finalFeedId, entryId: finalEntryId, timelineId: finalTimelineId })
|
||||
const navigate = getStableRouterNavigate()
|
||||
|
||||
const path = `/timeline/${finalTimelineId}/${finalFeedId}/${finalEntryId}`
|
||||
if (!navigate) {
|
||||
const message =
|
||||
"Navigation is not available, maybe a mistake in the code, please report an issue. thx."
|
||||
toast.error(message)
|
||||
throw new Error(message, { cause: "Navigation is not available" })
|
||||
}
|
||||
|
||||
const currentPath = route.location.pathname + route.location.search
|
||||
if (path === currentPath) return
|
||||
return getStableRouterNavigate()?.(path)
|
||||
return navigate?.(path)
|
||||
}
|
||||
|
||||
export const useBackHome = (timelineId?: string) => {
|
||||
|
||||
@@ -7,8 +7,9 @@ import { unreadSyncService } from "@follow/store/unread/store"
|
||||
import { EventBus } from "@follow/utils/event-bus"
|
||||
import { cn } from "@follow/utils/utils"
|
||||
import type { FC, PropsWithChildren } from "react"
|
||||
import { useCallback, useState } from "react"
|
||||
import { useCallback, useMemo, useState } from "react"
|
||||
import { useTranslation } from "react-i18next"
|
||||
import { NavLink } from "react-router"
|
||||
import { useDebounceCallback } from "usehooks-ts"
|
||||
|
||||
import {
|
||||
@@ -23,7 +24,7 @@ import { useEntryIsRead } from "~/hooks/biz/useAsRead"
|
||||
import { useContextMenuActionShortCutTrigger } from "~/hooks/biz/useContextMenuActionShortCutTrigger"
|
||||
import { useEntryActions } from "~/hooks/biz/useEntryActions"
|
||||
import { useFeedActions } from "~/hooks/biz/useFeedActions"
|
||||
import { useNavigateEntry } from "~/hooks/biz/useNavigateEntry"
|
||||
import { getNavigateEntryPath, useNavigateEntry } from "~/hooks/biz/useNavigateEntry"
|
||||
import { getRouteParams, useRouteParamsSelector } from "~/hooks/biz/useRouteParams"
|
||||
import { useContextMenu } from "~/hooks/common/useContextMenu"
|
||||
import { copyToClipboard } from "~/lib/clipboard"
|
||||
@@ -76,11 +77,20 @@ export const EntryItemWrapper: FC<
|
||||
)
|
||||
|
||||
const navigate = useNavigateEntry()
|
||||
|
||||
const navigationPath = useMemo(() => {
|
||||
if (!entry?.id) return "#"
|
||||
return getNavigateEntryPath({
|
||||
entryId: entry?.id,
|
||||
})
|
||||
}, [entry?.id])
|
||||
const handleClick = useCallback(
|
||||
(e) => {
|
||||
e.preventDefault()
|
||||
e.stopPropagation()
|
||||
|
||||
const shouldNavigate = getRouteParams().entryId !== entry?.id
|
||||
|
||||
if (!shouldNavigate) return
|
||||
if (!entry?.feedId) return
|
||||
if (!asRead) {
|
||||
@@ -98,7 +108,7 @@ export const EntryItemWrapper: FC<
|
||||
},
|
||||
[asRead, entry?.id, entry?.feedId, navigate],
|
||||
)
|
||||
const handleDoubleClick: React.MouseEventHandler<HTMLDivElement> = useCallback(
|
||||
const handleDoubleClick: React.MouseEventHandler<HTMLAnchorElement> = useCallback(
|
||||
() => entry?.url && window.open(entry.url, "_blank"),
|
||||
[entry?.url],
|
||||
)
|
||||
@@ -170,9 +180,10 @@ export const EntryItemWrapper: FC<
|
||||
|
||||
return (
|
||||
<div data-entry-id={entry?.id} style={style}>
|
||||
<div
|
||||
<NavLink
|
||||
to={navigationPath}
|
||||
className={cn(
|
||||
"hover:bg-theme-item-hover relative duration-200",
|
||||
"hover:bg-theme-item-hover cursor-button relative block duration-200",
|
||||
views[view as FeedViewType]?.wideMode ? "rounded-md" : "px-2",
|
||||
(isActive || isContextMenuOpen) && "!bg-theme-item-active",
|
||||
itemClassName,
|
||||
@@ -185,7 +196,7 @@ export const EntryItemWrapper: FC<
|
||||
{...(!isMobile ? { onTouchStart: handleClick } : {})}
|
||||
>
|
||||
{children}
|
||||
</div>
|
||||
</NavLink>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user