From 2f9f5a4f2025a0b4148d32205ecbe1ac4bed2a90 Mon Sep 17 00:00:00 2001 From: Innei Date: Fri, 24 Oct 2025 22:30:59 +0800 Subject: [PATCH] refactor(entry-content): replace legacy entry content with new preview component - Removed the legacy EntryContent component and replaced it with EntryContentForPreview in EntryModalPreview. - Updated AIChatContextBar to use a responsive max-width style. - These changes streamline the entry content rendering process and improve the overall code structure. Signed-off-by: Innei --- .../ui/peek-modal/EntryModalPreview.tsx | 4 +- .../components/layouts/AIChatContextBar.tsx | 2 +- .../entry-content/EntryContent.legacy.tsx | 391 ------------------ .../entry-content/EntryContentForPreview.tsx | 136 ++++++ 4 files changed, 139 insertions(+), 394 deletions(-) delete mode 100644 apps/desktop/layer/renderer/src/modules/entry-content/EntryContent.legacy.tsx create mode 100644 apps/desktop/layer/renderer/src/modules/entry-content/EntryContentForPreview.tsx diff --git a/apps/desktop/layer/renderer/src/components/ui/peek-modal/EntryModalPreview.tsx b/apps/desktop/layer/renderer/src/components/ui/peek-modal/EntryModalPreview.tsx index ae343bda4..57c179fff 100644 --- a/apps/desktop/layer/renderer/src/components/ui/peek-modal/EntryModalPreview.tsx +++ b/apps/desktop/layer/renderer/src/components/ui/peek-modal/EntryModalPreview.tsx @@ -1,7 +1,7 @@ import { usePrefetchEntryDetail } from "@follow/store/entry/hooks" import { Paper } from "~/components/ui/paper" -import { EntryContent as EntryContentLegacy } from "~/modules/entry-content/EntryContent.legacy" +import { EntryContentForPreview } from "~/modules/entry-content/EntryContentForPreview" export const EntryModalPreview = ({ entryId }: { entryId: string }) => { const { isPending } = usePrefetchEntryDetail(entryId) @@ -11,7 +11,7 @@ export const EntryModalPreview = ({ entryId }: { entryId: string }) => { {isPending ? ( ) : ( - diff --git a/apps/desktop/layer/renderer/src/modules/ai-chat/components/layouts/AIChatContextBar.tsx b/apps/desktop/layer/renderer/src/modules/ai-chat/components/layouts/AIChatContextBar.tsx index ef201b670..f0de0dc87 100644 --- a/apps/desktop/layer/renderer/src/modules/ai-chat/components/layouts/AIChatContextBar.tsx +++ b/apps/desktop/layer/renderer/src/modules/ai-chat/components/layouts/AIChatContextBar.tsx @@ -146,7 +146,7 @@ export const AIChatContextBar: Component = memo(({ className }) => { ? `combined-${item.viewBlock?.id}-${item.feedBlock?.id}-${item.unreadOnlyBlock?.id}` : item.block.id } - className="max-w-[240px] shrink-0" + className="max-w-[min(240px,100%)] shrink-0" > {renderBlock(item)} diff --git a/apps/desktop/layer/renderer/src/modules/entry-content/EntryContent.legacy.tsx b/apps/desktop/layer/renderer/src/modules/entry-content/EntryContent.legacy.tsx deleted file mode 100644 index b372db4a3..000000000 --- a/apps/desktop/layer/renderer/src/modules/entry-content/EntryContent.legacy.tsx +++ /dev/null @@ -1,391 +0,0 @@ -import { useGlobalFocusableScopeSelector } from "@follow/components/common/Focusable/hooks.js" -import { MemoedDangerousHTMLStyle } from "@follow/components/common/MemoedDangerousHTMLStyle.js" -import { Spring } from "@follow/components/constants/spring.js" -import { MotionButtonBase } from "@follow/components/ui/button/index.js" -import { RootPortal } from "@follow/components/ui/portal/index.js" -import { ScrollArea } from "@follow/components/ui/scroll-area/index.js" -import { FeedViewType } from "@follow/constants" -import { useTitle } from "@follow/hooks" -import { useEntry } from "@follow/store/entry/hooks" -import { useFeedById } from "@follow/store/feed/hooks" -import type { FeedModel } from "@follow/store/feed/types" -import { useIsInbox } from "@follow/store/inbox/hooks" -import { thenable } from "@follow/utils" -import { nextFrame, stopPropagation } from "@follow/utils/dom" -import { EventBus } from "@follow/utils/event-bus" -import { clsx, cn } from "@follow/utils/utils" -import { ErrorBoundary } from "@sentry/react" -import type { JSAnimation, Variants } from "motion/react" -import { AnimatePresence, m, useAnimationControls } from "motion/react" -import * as React from "react" -import { memo, useEffect, useMemo, useRef, useState } from "react" - -import { useEntryIsInReadability } from "~/atoms/readability" -import { useUISettingKey } from "~/atoms/settings/ui" -import { Focusable, FocusablePresets } from "~/components/common/Focusable" -import { ShadowDOM } from "~/components/common/ShadowDOM" -import type { TocRef } from "~/components/ui/markdown/components/Toc" -import { useInPeekModal } from "~/components/ui/modal/inspire/InPeekModal" -import { HotkeyScope } from "~/constants" -import { useNavigateEntry } from "~/hooks/biz/useNavigateEntry" -import { useRenderStyle } from "~/hooks/biz/useRenderStyle" -import { useRouteParamsSelector } from "~/hooks/biz/useRouteParams" -import { useFeedSafeUrl } from "~/hooks/common/useFeedSafeUrl" -import { COMMAND_ID } from "~/modules/command/commands/id" -import { EntryContentHTMLRenderer } from "~/modules/renderer/html" -import { WrappedElementProvider } from "~/providers/wrapped-element-provider" - -import { AISummary } from "./components/AISummary" -import { ApplyEntryActions } from "./components/ApplyEntryActions" -import { ContainerToc } from "./components/entry-content/accessories/ContainerToc" -import { EntryCommandShortcutRegister } from "./components/entry-content/EntryCommandShortcutRegister" -import { EntryContentFallback } from "./components/entry-content/EntryContentFallback" -import { EntryContentLoading } from "./components/entry-content/EntryContentLoading" -import { EntryNoContent } from "./components/entry-content/EntryNoContent" -import { EntryRenderError } from "./components/entry-content/EntryRenderError" -import { EntryScrollingAndNavigationHandler } from "./components/entry-content/EntryScrollingAndNavigationHandler.js" -import { EntryTitleMetaHandler } from "./components/entry-content/EntryTitleMetaHandler" -import { ReadabilityNotice } from "./components/entry-content/ReadabilityNotice" -import type { EntryContentProps } from "./components/entry-content/types" -import { EntryHeader } from "./components/entry-header" -import { EntryAttachments } from "./components/EntryAttachments" -import { EntryTitle } from "./components/EntryTitle" -import { SourceContentPanel } from "./components/SourceContentView" -import { NAVIGATION_HINTS_ICONS, NAVIGATION_HINTS_TEXT } from "./constants/navigation-hints" -import { useEntryContent, useEntryMediaInfo } from "./hooks" -import { useEntryNavigationHints } from "./hooks/useEntryNavigationHints" - -const pageMotionVariants = { - initial: { opacity: 0, y: 25 }, - animate: { opacity: 1, y: 0 }, - exit: { opacity: 0, y: 25, transition: { duration: 0 } }, -} satisfies Variants - -const EntryContentImpl: Component = ({ - entryId, - noMedia, - className, - compact, - classNames, -}) => { - const entry = useEntry(entryId, (state) => { - const { feedId, inboxHandle } = state - const { title, url } = state - - return { feedId, inboxId: inboxHandle, title, url } - }) - if (!entry) throw thenable - - useTitle(entry?.title) - - const feed = useFeedById(entry?.feedId) - - const isInbox = useIsInbox(entry?.inboxId) - const isInReadabilityMode = useEntryIsInReadability(entryId) - - const { error, content, isPending } = useEntryContent(entryId) - - const view = useRouteParamsSelector((route) => route.view) - const scrollerRef = useRef(null) - const safeUrl = useFeedSafeUrl(entryId) - const customCSS = useUISettingKey("customCSS") - - const isInPeekModal = useInPeekModal() - - const [panelPortalElement, setPanelPortalElement] = useState(null) - - const animationController = useAnimationControls() - const prevEntryId = useRef(undefined) - const scrollAnimationRef = useRef | null>(null) - useEffect(() => { - if (prevEntryId.current !== entryId) { - scrollAnimationRef.current?.stop() - nextFrame(() => { - scrollerRef.current?.scrollTo({ top: 0 }) - }) - animationController.start(pageMotionVariants.exit).then(() => { - animationController.start(pageMotionVariants.animate) - }) - prevEntryId.current = entryId - } - }, [animationController, entryId]) - - const isInHasTimelineView = ![ - FeedViewType.Pictures, - FeedViewType.SocialMedia, - FeedViewType.Videos, - ].includes(view) - - return ( - <> - - {!isInPeekModal && ( - - )} -
- - - - - - - - - {/* Indicator for the entry */} - - {isInHasTimelineView && !isInPeekModal && ( - <> -
- { - EventBus.dispatch(COMMAND_ID.timeline.switchToPrevious) - }} - > - - -
- -
- { - EventBus.dispatch(COMMAND_ID.timeline.switchToNext) - }} - > - - -
- - )} - -
- - - -
- - - - - - {!!customCSS && ( - {customCSS} - )} - - - - -
-
- - - - {!content && !isInReadabilityMode && ( -
- {isPending ? ( - - ) : error ? ( -
- - Network Error -
-                        {error.message}
-                      
-
- ) : ( - - )} -
- )} - - -
-
-
- -
- - ) -} -export const EntryContent: Component = memo((props) => { - return ( - - - - ) -}) - -const EntryScrollArea: Component<{ - scrollerRef: React.RefObject -}> = ({ children, className, scrollerRef }) => { - const isInPeekModal = useInPeekModal() - - if (isInPeekModal) { - return
{children}
- } - return ( - - {children} - - ) -} - -const Renderer: React.FC<{ - entryId: string - view: FeedViewType - feedId: string - noMedia?: boolean - content?: Nullable -}> = React.memo(({ entryId, view, feedId, noMedia = false, content = "" }) => { - const mediaInfo = useEntryMediaInfo(entryId) - - const readerRenderInlineStyle = useUISettingKey("readerRenderInlineStyle") - - const stableRenderStyle = useRenderStyle() - const isInPeekModal = useInPeekModal() - - const tocRef = useRef(null) - const contentAccessories = useMemo( - () => (isInPeekModal ? undefined : ), - [isInPeekModal], - ) - - useEffect(() => { - if (tocRef) { - tocRef.current?.refreshItems() - } - }, [content, tocRef]) - return ( - - {content} - - ) -}) - -// EntryNavigationHandler for legacy version (without wheel gesture) -const EntryNavigationHandler = ({ entryId }: { entryId: string }) => { - const navigate = useNavigateEntry() - const when = useGlobalFocusableScopeSelector(FocusablePresets.isEntryRender) - - // Handle close gesture - const handleCloseEntry = React.useCallback(() => { - navigate({ entryId: null }) - }, [navigate]) - - // Navigation hints for entry content (legacy version without wheel gesture) - const { showFirstEntryHint, showScrollHint, showBottomHint } = useEntryNavigationHints({ - enabled: when && !!entryId, - entryId, - }) - - // Render hint button with different states - const renderHintButton = (icon: string, text: string, position: "top" | "bottom" = "top") => ( - - - - ) - - return ( - - {/* First entry hint */} - {showFirstEntryHint && - renderHintButton( - NAVIGATION_HINTS_ICONS.ARROW_UP, - NAVIGATION_HINTS_TEXT.SCROLL_UP_EXIT, - "top", - )} - - {/* Scroll threshold hint */} - {showScrollHint && - renderHintButton( - NAVIGATION_HINTS_ICONS.ARROW_UP, - NAVIGATION_HINTS_TEXT.SCROLL_UP_EXIT, - "top", - )} - - {/* Bottom hint */} - {showBottomHint && - renderHintButton(NAVIGATION_HINTS_ICONS.CLOSE, NAVIGATION_HINTS_TEXT.ESC_EXIT, "bottom")} - - ) -} diff --git a/apps/desktop/layer/renderer/src/modules/entry-content/EntryContentForPreview.tsx b/apps/desktop/layer/renderer/src/modules/entry-content/EntryContentForPreview.tsx new file mode 100644 index 000000000..903a3b95b --- /dev/null +++ b/apps/desktop/layer/renderer/src/modules/entry-content/EntryContentForPreview.tsx @@ -0,0 +1,136 @@ +import type { FeedViewType } from "@follow/constants" +import { useEntry } from "@follow/store/entry/hooks" +import { useFeedById } from "@follow/store/feed/hooks" +import type { FeedModel } from "@follow/store/feed/types" +import { useIsInbox } from "@follow/store/inbox/hooks" +import { thenable } from "@follow/utils" +import { stopPropagation } from "@follow/utils/dom" +import { clsx } from "@follow/utils/utils" +import { ErrorBoundary } from "@sentry/react" +import * as React from "react" +import { memo } from "react" + +import { useEntryIsInReadability } from "~/atoms/readability" +import { useUISettingKey } from "~/atoms/settings/ui" +import { ShadowDOM } from "~/components/common/ShadowDOM" +import { useRenderStyle } from "~/hooks/biz/useRenderStyle" +import { useRouteParamsSelector } from "~/hooks/biz/useRouteParams" +import { EntryContentHTMLRenderer } from "~/modules/renderer/html" +import { WrappedElementProvider } from "~/providers/wrapped-element-provider" + +import { EntryContentFallback } from "./components/entry-content/EntryContentFallback" +import { EntryContentLoading } from "./components/entry-content/EntryContentLoading" +import { EntryNoContent } from "./components/entry-content/EntryNoContent" +import { EntryRenderError } from "./components/entry-content/EntryRenderError" +import type { EntryContentProps } from "./components/entry-content/types" +import { EntryAttachments } from "./components/EntryAttachments" +import { EntryTitle } from "./components/EntryTitle" +import { useEntryContent, useEntryMediaInfo } from "./hooks" + +const EntryContentImpl: Component = ({ + entryId, + noMedia, + + compact, +}) => { + const entry = useEntry(entryId, (state) => { + const { feedId, inboxHandle } = state + const { title, url } = state + + return { feedId, inboxId: inboxHandle, title, url } + }) + if (!entry) throw thenable + + const feed = useFeedById(entry?.feedId) + + const isInbox = useIsInbox(entry?.inboxId) + const isInReadabilityMode = useEntryIsInReadability(entryId) + + const { error, content, isPending } = useEntryContent(entryId) + + const view = useRouteParamsSelector((route) => route.view) + + return ( +
+
+ + + +
+ + + + + +
+
+ + {!content && !isInReadabilityMode && ( +
+ {isPending ? ( + + ) : error ? ( +
+ + Network Error +
+                  {error.message}
+                
+
+ ) : ( + + )} +
+ )} + + +
+
+ ) +} +export const EntryContentForPreview: Component = memo((props) => { + return ( + + + + ) +}) + +const Renderer: React.FC<{ + entryId: string + view: FeedViewType + feedId: string + noMedia?: boolean + content?: Nullable +}> = React.memo(({ entryId, view, feedId, noMedia = false, content = "" }) => { + const mediaInfo = useEntryMediaInfo(entryId) + + const readerRenderInlineStyle = useUISettingKey("readerRenderInlineStyle") + + const stableRenderStyle = useRenderStyle() + + return ( + + {content} + + ) +})