refactor(entry-header): restructure entry header components for improved context management
This commit is contained in:
+1
-2
@@ -115,7 +115,6 @@ const EntryContentImpl: Component<EntryContentProps> = ({
|
||||
<EntryCommandShortcutRegister entryId={entryId} view={view} />
|
||||
<AIEntryHeader
|
||||
entryId={entryId}
|
||||
view={view}
|
||||
className={cn("@container h-[55px] shrink-0 px-3", classNames?.header)}
|
||||
compact={compact}
|
||||
/>
|
||||
@@ -134,7 +133,7 @@ const EntryContentImpl: Component<EntryContentProps> = ({
|
||||
<EntryTimeline entryId={entryId} />
|
||||
<EntryScrollArea scrollerRef={scrollerRef}>
|
||||
{/* Indicator for the entry */}
|
||||
<div className="select-text">
|
||||
<div className="mt-12 select-text">
|
||||
{!isZenMode && isInHasTimelineView && (
|
||||
<>
|
||||
<div className="absolute inset-y-0 left-0 z-[9] flex w-12 items-center justify-center opacity-40 duration-200 hover:opacity-100">
|
||||
|
||||
+2
-2
@@ -42,7 +42,7 @@ import { EntryTimelineSidebar } from "../EntryTimelineSidebar"
|
||||
import { EntryTitle } from "../EntryTitle"
|
||||
import { SourceContentPanel } from "../SourceContentView"
|
||||
import { SupportCreator } from "../SupportCreator"
|
||||
import { EntryContentAccessories } from "./accessories"
|
||||
import { ContainerToc } from "./accessories/ContainerToc"
|
||||
import { EntryCommandShortcutRegister } from "./EntryCommandShortcutRegister"
|
||||
import { EntryContentLoading } from "./EntryContentLoading"
|
||||
import { EntryNoContent } from "./EntryNoContent"
|
||||
@@ -284,7 +284,7 @@ const Renderer: React.FC<{
|
||||
|
||||
const tocRef = useRef<TocRef | null>(null)
|
||||
const contentAccessories = useMemo(
|
||||
() => (isInPeekModal ? undefined : <EntryContentAccessories ref={{ tocRef }} />),
|
||||
() => (isInPeekModal ? undefined : <ContainerToc ref={tocRef} />),
|
||||
[isInPeekModal],
|
||||
)
|
||||
|
||||
|
||||
+14
-3
@@ -95,16 +95,27 @@ const BackTopIndicator: Component = memo(({ className }) => {
|
||||
})
|
||||
|
||||
export const ContainerToc = memo(
|
||||
({ ref, ..._ }: ComponentType & { ref?: React.Ref<TocRef | null> }) => {
|
||||
({
|
||||
ref,
|
||||
className,
|
||||
stickyClassName,
|
||||
}: ComponentType & {
|
||||
ref?: React.Ref<TocRef | null>
|
||||
className?: string
|
||||
stickyClassName?: string
|
||||
}) => {
|
||||
const wrappedElement = useWrappedElement()
|
||||
|
||||
return (
|
||||
<RootPortal to={wrappedElement!}>
|
||||
<div
|
||||
className="@[770px]:block group absolute right-[-130px] top-0 hidden h-full w-[100px]"
|
||||
className={cn(
|
||||
"@[770px]:block group absolute right-[-130px] top-0 hidden h-full w-[100px]",
|
||||
className,
|
||||
)}
|
||||
data-hide-in-print
|
||||
>
|
||||
<div className="sticky top-0">
|
||||
<div className={cn("sticky top-0", stickyClassName)}>
|
||||
<Toc
|
||||
ref={ref}
|
||||
className={cn(
|
||||
|
||||
+15
-9
@@ -1,17 +1,23 @@
|
||||
import { memo } from "react"
|
||||
|
||||
import { BaseEntryHeader } from "./internal/BaseEntryHeader"
|
||||
import { EntryHeaderRoot } from "./internal/context"
|
||||
import { EntryHeaderActionsContainer } from "./internal/EntryHeaderActionsContainer"
|
||||
import { EntryHeaderMeta } from "./internal/EntryHeaderMeta"
|
||||
import { EntryHeaderReadHistory } from "./internal/EntryHeaderReadHistory"
|
||||
import type { EntryHeaderProps } from "./types"
|
||||
|
||||
function EntryHeaderImpl({ view, entryId, className, compact }: EntryHeaderProps) {
|
||||
function EntryHeaderImpl({ entryId, className, compact }: EntryHeaderProps) {
|
||||
return (
|
||||
<BaseEntryHeader
|
||||
view={view}
|
||||
entryId={entryId}
|
||||
className={className}
|
||||
compact={compact}
|
||||
config={{ alwaysShowActions: true }}
|
||||
/>
|
||||
<EntryHeaderRoot entryId={entryId} className={className} compact={compact}>
|
||||
<EntryHeaderReadHistory />
|
||||
<div
|
||||
className="relative z-10 flex w-full items-center justify-between gap-3"
|
||||
data-hide-in-print
|
||||
>
|
||||
<EntryHeaderMeta />
|
||||
<EntryHeaderActionsContainer />
|
||||
</div>
|
||||
</EntryHeaderRoot>
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
+15
-9
@@ -1,17 +1,23 @@
|
||||
import { memo } from "react"
|
||||
|
||||
import { BaseEntryHeader } from "./internal/BaseEntryHeader"
|
||||
import { EntryHeaderRoot } from "./internal/context"
|
||||
import { EntryHeaderActionsContainer } from "./internal/EntryHeaderActionsContainer"
|
||||
import { EntryHeaderMeta } from "./internal/EntryHeaderMeta"
|
||||
import { EntryHeaderReadHistory } from "./internal/EntryHeaderReadHistory"
|
||||
import type { EntryHeaderProps } from "./types"
|
||||
|
||||
function EntryHeaderImpl({ view, entryId, className, compact }: EntryHeaderProps) {
|
||||
function EntryHeaderImpl({ entryId, className, compact }: EntryHeaderProps) {
|
||||
return (
|
||||
<BaseEntryHeader
|
||||
view={view}
|
||||
entryId={entryId}
|
||||
className={className}
|
||||
compact={compact}
|
||||
config={{ showActionsWhenWide: false }}
|
||||
/>
|
||||
<EntryHeaderRoot entryId={entryId} className={className} compact={compact}>
|
||||
<EntryHeaderReadHistory />
|
||||
<div
|
||||
className="relative z-10 flex w-full items-center justify-between gap-3"
|
||||
data-hide-in-print
|
||||
>
|
||||
<EntryHeaderMeta />
|
||||
<EntryHeaderActionsContainer />
|
||||
</div>
|
||||
</EntryHeaderRoot>
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
export * from "./AIEntryHeader"
|
||||
export * from "./EntryHeader"
|
||||
export * from "./internal/context"
|
||||
export * from "./internal/EntryHeaderActionsContainer"
|
||||
export * from "./internal/EntryHeaderMeta"
|
||||
export * from "./internal/EntryHeaderReadHistory"
|
||||
export * from "./types"
|
||||
|
||||
-74
@@ -1,74 +0,0 @@
|
||||
import type { FeedViewType } from "@follow/constants"
|
||||
import { views } from "@follow/constants"
|
||||
import { useHasEntry } from "@follow/store/entry/hooks"
|
||||
import { cn } from "@follow/utils/utils"
|
||||
import { memo } from "react"
|
||||
|
||||
import { useUISettingKey } from "~/atoms/settings/ui"
|
||||
|
||||
import { useEntryContentScrollToTop, useEntryTitleMeta } from "../../../atoms"
|
||||
import { EntryHeaderActionsContainer } from "./EntryHeaderActionsContainer"
|
||||
import { EntryHeaderMeta } from "./EntryHeaderMeta"
|
||||
import { EntryHeaderReadHistory } from "./EntryHeaderReadHistory"
|
||||
|
||||
interface EntryHeaderConfig {
|
||||
showActionsWhenWide?: boolean
|
||||
alwaysShowActions?: boolean
|
||||
}
|
||||
|
||||
interface BaseEntryHeaderProps {
|
||||
view: FeedViewType
|
||||
entryId: string
|
||||
className?: string
|
||||
compact?: boolean
|
||||
config?: EntryHeaderConfig
|
||||
}
|
||||
|
||||
function BaseEntryHeaderImpl({ view, entryId, className, compact, config }: BaseEntryHeaderProps) {
|
||||
const hasEntry = useHasEntry(entryId)
|
||||
const entryTitleMeta = useEntryTitleMeta()
|
||||
const isAtTop = useEntryContentScrollToTop()
|
||||
const hideRecentReader = useUISettingKey("hideRecentReader")
|
||||
|
||||
const shouldShowMeta = !isAtTop && !!entryTitleMeta?.title
|
||||
const isWide = views[view]?.wideMode
|
||||
|
||||
const shouldShowActions =
|
||||
config?.alwaysShowActions ?? (config?.showActionsWhenWide ? true : !isWide)
|
||||
|
||||
if (!hasEntry) return null
|
||||
|
||||
return (
|
||||
<div
|
||||
data-hide-in-print
|
||||
className={cn(
|
||||
"zen-mode-macos:ml-margin-macos-traffic-light-x text-text-secondary relative flex min-w-0 items-center justify-between gap-3 overflow-hidden text-lg duration-200",
|
||||
shouldShowMeta && "border-border border-b",
|
||||
className,
|
||||
)}
|
||||
>
|
||||
<EntryHeaderReadHistory
|
||||
entryId={entryId}
|
||||
view={view}
|
||||
shouldShow={!hideRecentReader}
|
||||
shouldHide={shouldShowMeta}
|
||||
/>
|
||||
|
||||
<div
|
||||
className="relative z-10 flex w-full items-center justify-between gap-3"
|
||||
data-hide-in-print
|
||||
>
|
||||
<EntryHeaderMeta entryTitleMeta={entryTitleMeta} shouldShow={shouldShowMeta} />
|
||||
|
||||
<EntryHeaderActionsContainer
|
||||
entryId={entryId}
|
||||
view={view}
|
||||
compact={compact}
|
||||
shouldShow={shouldShowActions}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export const BaseEntryHeader = memo(BaseEntryHeaderImpl)
|
||||
+12
-15
@@ -1,23 +1,20 @@
|
||||
import type { FeedViewType } from "@follow/constants"
|
||||
import { views } from "@follow/constants"
|
||||
import { memo } from "react"
|
||||
|
||||
import { useRouteParams } from "~/hooks/biz/useRouteParams"
|
||||
|
||||
import { EntryHeaderActions } from "../../../actions/header-actions"
|
||||
import { MoreActions } from "../../../actions/more-actions"
|
||||
import { useEntryContentScrollToTop } from "../../../atoms"
|
||||
import { useEntryHeaderContext } from "./context"
|
||||
|
||||
interface EntryHeaderActionsContainerProps {
|
||||
entryId: string
|
||||
view: FeedViewType
|
||||
compact?: boolean
|
||||
shouldShow: boolean
|
||||
}
|
||||
|
||||
function EntryHeaderActionsContainerImpl({
|
||||
entryId,
|
||||
view,
|
||||
compact,
|
||||
shouldShow,
|
||||
}: EntryHeaderActionsContainerProps) {
|
||||
if (!shouldShow) return null
|
||||
function EntryHeaderActionsContainerImpl() {
|
||||
const { entryId, compact } = useEntryHeaderContext()
|
||||
const { view } = useRouteParams()
|
||||
const isAtTop = useEntryContentScrollToTop()
|
||||
const isWide = views[view]?.wideMode
|
||||
const shouldShowActions = !isWide || !isAtTop
|
||||
if (!shouldShowActions) return null
|
||||
|
||||
return (
|
||||
<div className="relative flex shrink-0 items-center justify-end gap-2">
|
||||
|
||||
+6
-11
@@ -1,21 +1,16 @@
|
||||
import { AnimatePresence, m } from "motion/react"
|
||||
import { memo } from "react"
|
||||
|
||||
interface EntryTitleMeta {
|
||||
title: string
|
||||
description?: string
|
||||
}
|
||||
import { useEntryContentScrollToTop, useEntryTitleMeta } from "../../../atoms"
|
||||
|
||||
interface EntryHeaderMetaProps {
|
||||
entryTitleMeta: Nullable<EntryTitleMeta>
|
||||
shouldShow: boolean
|
||||
}
|
||||
|
||||
function EntryHeaderMetaImpl({ entryTitleMeta, shouldShow }: EntryHeaderMetaProps) {
|
||||
function EntryHeaderMetaImpl() {
|
||||
const entryTitleMeta = useEntryTitleMeta()
|
||||
const isAtTop = useEntryContentScrollToTop()
|
||||
const shouldShowMeta = !isAtTop && !!entryTitleMeta?.title
|
||||
return (
|
||||
<div className="flex min-w-0 shrink grow">
|
||||
<AnimatePresence>
|
||||
{shouldShow && entryTitleMeta && (
|
||||
{shouldShowMeta && entryTitleMeta && (
|
||||
<m.div
|
||||
initial={{ opacity: 0.01, y: 30 }}
|
||||
animate={{ opacity: 1, y: 0 }}
|
||||
|
||||
+11
-17
@@ -1,32 +1,26 @@
|
||||
import type { FeedViewType } from "@follow/constants"
|
||||
import { views } from "@follow/constants"
|
||||
import { cn } from "@follow/utils/utils"
|
||||
import { memo } from "react"
|
||||
|
||||
import { useRouteParams } from "~/hooks/biz/useRouteParams"
|
||||
|
||||
import { useEntryContentScrollToTop } from "../../../atoms"
|
||||
import { EntryReadHistory } from "../../entry-read-history"
|
||||
import { useEntryHeaderContext } from "./context"
|
||||
|
||||
interface EntryHeaderReadHistoryProps {
|
||||
entryId: string
|
||||
view: FeedViewType
|
||||
shouldShow: boolean
|
||||
shouldHide: boolean
|
||||
}
|
||||
|
||||
function EntryHeaderReadHistoryImpl({
|
||||
entryId,
|
||||
view,
|
||||
shouldShow,
|
||||
shouldHide,
|
||||
}: EntryHeaderReadHistoryProps) {
|
||||
if (!shouldShow) return null
|
||||
function EntryHeaderReadHistoryImpl() {
|
||||
const { entryId } = useEntryHeaderContext()
|
||||
const { view } = useRouteParams()
|
||||
const isAtTop = useEntryContentScrollToTop()
|
||||
const isWide = views[view]?.wideMode
|
||||
if (isAtTop) return null
|
||||
|
||||
return (
|
||||
<div
|
||||
className={cn(
|
||||
"zen-mode-macos:left-12 text-body absolute left-5 top-0 flex h-full items-center gap-2 leading-none",
|
||||
"visible z-[11]",
|
||||
views[view]?.wideMode && "static",
|
||||
shouldHide && "hidden",
|
||||
isWide && "static",
|
||||
)}
|
||||
>
|
||||
<EntryReadHistory entryId={entryId} />
|
||||
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
import { useHasEntry } from "@follow/store/entry/hooks"
|
||||
import { cn } from "@follow/utils/utils"
|
||||
import type { ReactNode } from "react"
|
||||
import { createContext, memo, use, useMemo } from "react"
|
||||
|
||||
import { useEntryContentScrollToTop, useEntryTitleMeta } from "../../../atoms"
|
||||
import type { EntryHeaderProps } from "../types"
|
||||
|
||||
interface EntryHeaderContextValue {
|
||||
entryId: string
|
||||
compact?: boolean
|
||||
}
|
||||
|
||||
const EntryHeaderContext = createContext<EntryHeaderContextValue | null>(null)
|
||||
|
||||
export function useEntryHeaderContext() {
|
||||
const ctx = use(EntryHeaderContext)
|
||||
if (!ctx) throw new Error("EntryHeader components must be used within <EntryHeaderRoot />")
|
||||
return ctx
|
||||
}
|
||||
|
||||
export interface EntryHeaderRootProps extends EntryHeaderProps {
|
||||
children: ReactNode
|
||||
}
|
||||
|
||||
function EntryHeaderRootImpl({ entryId, className, compact, children }: EntryHeaderRootProps) {
|
||||
const hasEntry = useHasEntry(entryId)
|
||||
const entryTitleMeta = useEntryTitleMeta()
|
||||
const isAtTop = !!useEntryContentScrollToTop()
|
||||
|
||||
const shouldShowMeta = !isAtTop && !!entryTitleMeta?.title
|
||||
|
||||
const contextValue = useMemo(() => ({ entryId, compact }), [entryId, compact])
|
||||
if (!hasEntry) return null
|
||||
|
||||
return (
|
||||
<EntryHeaderContext value={contextValue}>
|
||||
<div
|
||||
data-hide-in-print
|
||||
className={cn(
|
||||
"zen-mode-macos:ml-margin-macos-traffic-light-x text-text-secondary relative flex min-w-0 items-center justify-between gap-3 overflow-hidden text-lg duration-200",
|
||||
shouldShowMeta && "border-border border-b",
|
||||
className,
|
||||
)}
|
||||
>
|
||||
{children}
|
||||
</div>
|
||||
</EntryHeaderContext>
|
||||
)
|
||||
}
|
||||
|
||||
export const EntryHeaderRoot = memo(EntryHeaderRootImpl)
|
||||
-3
@@ -1,7 +1,4 @@
|
||||
import type { FeedViewType } from "@follow/constants"
|
||||
|
||||
export interface EntryHeaderProps {
|
||||
view: FeedViewType
|
||||
entryId: string
|
||||
className?: string
|
||||
compact?: boolean
|
||||
|
||||
+2
-2
@@ -21,7 +21,7 @@ import { WrappedElementProvider } from "~/providers/wrapped-element-provider"
|
||||
|
||||
import { AISummary } from "../../AISummary"
|
||||
import { useEntryContent, useEntryMediaInfo } from "../../hooks"
|
||||
import { EntryContentAccessories } from "../entry-content/accessories"
|
||||
import { ContainerToc } from "../entry-content/accessories/ContainerToc"
|
||||
import { EntryRenderError } from "../entry-content/EntryRenderError"
|
||||
import { EntryTitleMetaHandler } from "../entry-content/EntryTitleMetaHandler"
|
||||
import { ReadabilityNotice } from "../entry-content/ReadabilityNotice"
|
||||
@@ -129,7 +129,7 @@ const Renderer: React.FC<{
|
||||
|
||||
const tocRef = useRef<TocRef | null>(null)
|
||||
const contentAccessories = useMemo(
|
||||
() => (isInPeekModal ? undefined : <EntryContentAccessories ref={{ tocRef }} />),
|
||||
() => (isInPeekModal ? undefined : <ContainerToc ref={tocRef} stickyClassName="top-28" />),
|
||||
[isInPeekModal],
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user