feat: new design ai layout (#4448)

* init

Signed-off-by: Innei <tukon479@gmail.com>

* feat(ai): add showSplineButton setting and update UI components

- Introduced a new setting `showSplineButton` to control the visibility of the AI assistant indicator.
- Updated the `createDefaultSettings` function to include the new setting with a default value of true.
- Modified the `AISplineButton` component to conditionally render based on the `showSplineButton` setting.
- Adjusted the modal content width in the `useDialog` hook for better layout.
- Enhanced the settings tab to define the new `showSplineButton` item with appropriate labels and descriptions.
- Updated localization files to include translations for the new setting.

These changes improve user control over the AI assistant's visibility and enhance the overall UI experience.

Signed-off-by: Innei <tukon479@gmail.com>

* feat(ai): implement AISmartSidebar with CSS animations

- Added AISmartSidebar component to replace motion/react animations with CSS animations for improved performance and visual effects.
- Introduced corresponding AISmartSidebar.css file to define animations and styles for the sidebar elements.
- Updated AISplineButton to conditionally render AISmartSidebar based on visibility settings.
- Refactored AIEntryLayout to use the new AIIndicator component, enhancing the integration of the sidebar.

These changes enhance the user experience by providing smoother animations and better control over the AI assistant's visibility.

Signed-off-by: Innei <tukon479@gmail.com>

* refactor(ui): update icon usage and improve layout spacing

- Replaced icons in the EntryMoreActions and MoreActions components for consistency.
- Adjusted padding and margin in various components, including AIEntryHeader and SubscriptionColumn, to enhance layout and visual appeal.
- Added a new label 'View' to the ai-block-constants for better clarity.

These changes improve the overall user interface and maintain consistency across components.

Signed-off-by: Innei <tukon479@gmail.com>

* refactor(ui): enhance ChatHeader and EntryListHeader layouts

- Updated the ChatHeaderLayout to conditionally render styles based on the floating state, improving visual consistency.
- Adjusted the EntryListHeader component to set a fixed height, ensuring uniformity in layout across different views.

These changes improve the overall user interface and maintain a consistent layout experience.

Signed-off-by: Innei <tukon479@gmail.com>

* refactor(ui): update ChatHeader and ChatMoreDropdown components

- Replaced GlassButton with ActionButton in ChatHeader for improved consistency and styling.
- Simplified the rendering of TaskReportDropdown and ChatMoreDropdown components.
- Adjusted layout styles in WelcomeScreen for better alignment.
- Enhanced ChatInterface to improve input positioning when no messages are present.

These changes enhance the user interface and maintain a consistent look across components.

Signed-off-by: Innei <tukon479@gmail.com>

* refactor(ai): adjust AI chat layout width for improved styling

- Updated the AI chat component to set a custom layout width of 65rem, enhancing the overall appearance and usability of the chat interface.

This change aims to provide a more consistent and visually appealing layout for the AI chat experience.

Signed-off-by: Innei <tukon479@gmail.com>

* refactor(ui): adjust spacing in EntryListHeader component

- Increased the gap between items in the EntryListHeader from 1 to 2 for improved layout and visual consistency.

This change enhances the overall user interface by providing better spacing in the header layout.

Signed-off-by: Innei <tukon479@gmail.com>

---------

Signed-off-by: Innei <tukon479@gmail.com>
This commit is contained in:
Innei
2025-09-05 23:22:15 +08:00
committed by GitHub
parent 7d0a0d1c40
commit 0e07f59c6a
38 changed files with 1036 additions and 308 deletions
@@ -7,11 +7,13 @@ import { atom, useAtomValue } from "jotai"
export interface WebAISettings extends AISettings {
panelStyle: AIChatPanelStyle
showSplineButton: boolean
}
export const createDefaultSettings = (): WebAISettings => ({
...defaultAISettings,
panelStyle: AIChatPanelStyle.Fixed,
showSplineButton: true,
})
export const {
@@ -70,7 +70,7 @@ export const AISummaryCardBase: React.FC<AISummaryCardBaseProps> = ({
"group relative overflow-hidden rounded-2xl border border-neutral-200/50 p-5 backdrop-blur-xl",
"bg-gradient-to-b from-neutral-50/80 to-white/40 dark:from-neutral-900/80 dark:to-neutral-900/40",
"dark:border-neutral-800/50",
"shadow-[0_8px_32px_rgba(0,0,0,0.08)] dark:shadow-[0_8px_32px_rgba(0,0,0,0.3)]",
isLoading &&
"before:absolute before:inset-0 before:-z-10 before:animate-[pulse_2s_cubic-bezier(0.4,0,0.6,1)_infinite] before:bg-gradient-to-r before:from-purple-100/0 before:via-purple-300/10 before:to-purple-100/0 dark:before:from-purple-900/0 dark:before:via-purple-600/10 dark:before:to-purple-900/0",
className,
@@ -165,7 +165,7 @@ export const useDialog = (): DialogInstance => {
</div>
),
content: ({ dismiss }) => (
<div className="flex max-w-prose flex-col gap-3">
<div className="flex max-w-[45ch] flex-col gap-3">
<div className="whitespace-pre text-wrap">{options.message}</div>
<div className="flex items-center justify-end gap-3">
@@ -49,7 +49,7 @@ export const EntryMoreActions: FC<{ entryId: string }> = ({ entryId }) => {
return (
<DropdownMenu>
<DropdownMenuTrigger asChild>
<i className="i-mgc-more-1-cute-re" />
<i className="i-mingcute-more-1-fill" />
</DropdownMenuTrigger>
<RootPortal>
<DropdownMenuContent alignOffset={20} sideOffset={30}>
@@ -66,7 +66,8 @@ export const AIModelIndicator = memo(({ className, onModelChange }: AIModelIndic
? "hover:bg-material-medium cursor-button"
: "hover:bg-material-medium/50",
"duration-200",
"gap-1.5 px-2 py-1 text-xs",
"gap-1.5 p-1 text-xs",
hasMultipleModels && "px-2",
"bg-material-ultra-thin border-border/50",
"text-text-secondary",
@@ -0,0 +1,60 @@
/* CSS animations for AISmartSidebar (replacing motion/react) */
.ai-ambient-bar {
transform-origin: right center;
transition:
width 0.3s ease-out,
opacity 0.3s ease-out,
transform 0.3s ease-out;
}
@keyframes ai-bar-pulse {
0%,
100% {
transform: scale(1);
}
50% {
transform: scale(1.1);
}
}
.ai-ambient-pulse {
animation: ai-bar-pulse 2s ease-in-out infinite;
}
.ai-glow-blob {
transition:
opacity 0.3s cubic-bezier(0.22, 1, 0.36, 1),
transform 0.3s cubic-bezier(0.22, 1, 0.36, 1);
will-change: transform, opacity;
border-radius: 9999px;
}
.ai-prompt-container {
opacity: 0;
transform: translateX(20px);
transition:
opacity 0.25s cubic-bezier(0.22, 1, 0.36, 1),
transform 0.25s cubic-bezier(0.22, 1, 0.36, 1);
}
.ai-prompt-visible {
opacity: 1;
transform: translateX(0);
}
@keyframes ai-dot-pulse-kf {
0%,
100% {
transform: scale(1);
opacity: 0.7;
}
50% {
transform: scale(1.2);
opacity: 1;
}
}
.ai-dot-pulse {
animation: ai-dot-pulse-kf 2s ease-in-out infinite;
}
@@ -0,0 +1,117 @@
// Replaced motion/react animations with CSS animations
import "./AISmartSidebar.css"
import { Spring } from "@follow/components/constants/spring.js"
import { useMousePosition } from "@follow/components/hooks/useMouse.js"
import { AnimatePresence, m } from "motion/react"
import * as React from "react"
import { useEffect, useState } from "react"
import { setAIPanelVisibility, useAIPanelVisibility } from "~/atoms/settings/ai"
const AIAmbientSidebar: React.FC<{ onExpand: () => void }> = ({ onExpand }) => {
const [intensity, setIntensity] = useState(0)
const [showPrompt, setShowPrompt] = useState(false)
const isShowPromptRef = React.useRef(false)
const mousePosition = useMousePosition()
useEffect(() => {
const rightEdgeDistance = window.innerWidth - mousePosition.x
const maxDistance = 500
const threshold = 80
const showedThreshold = 300
const topBoundary = 100
if (mousePosition.y <= topBoundary) {
setIntensity(0)
setShowPrompt(false)
isShowPromptRef.current = false
return
}
if (isShowPromptRef.current && rightEdgeDistance <= showedThreshold) {
return
}
if (rightEdgeDistance <= maxDistance) {
const newIntensity = Math.max(0, (maxDistance - rightEdgeDistance) / maxDistance)
setIntensity(newIntensity)
const shouldShow = rightEdgeDistance <= threshold
setShowPrompt(shouldShow)
isShowPromptRef.current = shouldShow
} else {
setIntensity(0)
setShowPrompt(false)
isShowPromptRef.current = false
}
}, [mousePosition])
return (
<>
<div
className={`ai-ambient-bar pointer-events-none fixed right-0 top-0 z-40 h-full w-2 ${
intensity > 0.3 ? "ai-ambient-pulse" : ""
}`}
style={{
opacity: intensity * 0.8,
width: intensity > 0 ? 8 + intensity * 40 : 2,
background: `linear-gradient(to left, rgba(255, 92, 0, ${intensity * 0.4}) 0%, rgba(255, 140, 0, ${intensity * 0.3}) 50%, transparent 100%)`,
}}
/>
<AnimatePresence>
{showPrompt && (
<>
<m.div
initial={{ opacity: 0, scale: 0.5, x: 0 }}
animate={{
opacity: intensity * 0.6,
scale: 0.5 + intensity * 1.5,
x: intensity > 0 ? -10 - intensity * 30 : 0,
}}
exit={{ opacity: 0, scale: 0.5, x: 0 }}
transition={Spring.presets.smooth}
className="ai-glow-blob pointer-events-none fixed bottom-12 right-0 z-40"
style={{
opacity: intensity * 0.6,
transform: `translateX(${intensity > 0 ? -10 - intensity * 30 : 0}px) scale(${0.5 + intensity * 1.5})`,
width: 100,
height: 100,
background: `radial-gradient(circle, rgba(255, 92, 0, ${intensity * 0.3}) 0%, rgba(255, 140, 0, ${intensity * 0.2}) 40%, transparent 70%)`,
}}
/>
<m.div
initial={{ opacity: 0, x: 20 }}
animate={{ opacity: 1, x: 0 }}
exit={{ opacity: 0, x: 20 }}
className="ai-prompt-container ai-prompt-visible fixed bottom-12 right-6 z-50 flex flex-col items-end gap-3"
>
<div className="bg-background/90 border-folo/30 rounded-2xl border px-4 py-3 backdrop-blur-xl">
<div className="text-right">
<p className="text-text text-sm font-medium">Ask AI anything</p>
<p className="text-text-secondary mt-1 text-xs">
Get insights about this article
</p>
</div>
</div>
<button
type="button"
className="border-folo/40 from-folo/20 hover:from-folo/30 rounded-full border bg-gradient-to-r to-red-500/20 px-6 py-2 backdrop-blur-xl transition-all duration-300 hover:to-red-500/30"
onClick={onExpand}
>
<div className="flex items-center gap-2">
<div className="from-folo ai-dot-pulse size-2 rounded-full bg-gradient-to-r to-red-500" />
<span className="text-text text-sm font-medium">Open AI Chat</span>
</div>
</button>
</m.div>
</>
)}
</AnimatePresence>
</>
)
}
export const AISmartSidebar: React.FC = () =>
!useAIPanelVisibility() && <AIAmbientSidebar onExpand={() => setAIPanelVisibility(true)} />
@@ -1,9 +1,9 @@
import { ActionButton } from "@follow/components/ui/button/index.js"
import clsx from "clsx"
import type { ReactNode } from "react"
import { useCallback } from "react"
import { AIChatPanelStyle, setAIPanelVisibility, useAIChatPanelStyle } from "~/atoms/settings/ai"
import { GlassButton } from "~/components/ui/button/GlassButton"
import { useBlockActions, useChatActions, useCurrentTitle } from "~/modules/ai-chat/store/hooks"
import { ChatMoreDropdown } from "./ChatMoreDropdown"
@@ -41,16 +41,23 @@ const ChatHeaderLayout = ({
[chatActions],
)
const maskImage = `linear-gradient(to bottom, black 0%, black 90%, transparent 100%)`
const isFloating = useAIChatPanelStyle() === AIChatPanelStyle.Floating
return (
<div className="absolute inset-x-0 top-0 z-[1] h-12">
<div
className="bg-background/70 backdrop-blur-background absolute inset-0"
style={{
maskImage,
WebkitMaskImage: maskImage,
}}
/>
<div
className={clsx(
"absolute inset-x-0 top-0 z-[1] h-12",
!isFloating && "bg-background border-b",
)}
>
{isFloating && (
<div
className="bg-background/70 backdrop-blur-background absolute inset-0"
style={{
maskImage: `linear-gradient(to bottom, black 0%, black 90%, transparent 100%)`,
}}
/>
)}
<div className="relative z-10 flex h-full items-center justify-between px-4">
<div className="mr-2 flex min-w-0 flex-1 items-center">
@@ -86,7 +93,7 @@ export const ChatHeader = () => {
<ChatMoreDropdown
triggerElement={
<ActionButton tooltip="More">
<i className="i-mingcute-more-1-fill size-5 opacity-80" />
<i className="i-mingcute-more-1-fill text-text-secondary size-5" />
</ActionButton>
}
/>
@@ -110,27 +117,19 @@ export const ChatPageHeader = () => {
<ChatHeaderLayout
renderActions={({ onNewChatClick }) => (
<>
<GlassButton description="New Chat" size="sm" onClick={onNewChatClick}>
<i className="i-mgc-add-cute-re text-text-secondary size-4" />
</GlassButton>
<ActionButton tooltip="New Chat" onClick={onNewChatClick}>
<i className="i-mgc-add-cute-re text-text-secondary size-5" />
</ActionButton>
<TaskReportDropdown
asChild={false}
triggerElement={
<GlassButton description="Task Reports" size="sm">
<i className="i-mgc-inbox-cute-re text-text-secondary size-4" />
</GlassButton>
}
/>
<TaskReportDropdown />
<div className="bg-border mx-2 h-5 w-px" />
<ChatMoreDropdown
canToggleMode={false}
asChild={false}
triggerElement={
<GlassButton description="More" size="sm">
<i className="i-mingcute-more-1-fill size-4 opacity-80" />
</GlassButton>
<ActionButton tooltip="More">
<i className="i-mingcute-more-1-fill text-text-secondary size-5" />
</ActionButton>
}
/>
</>
@@ -283,7 +283,9 @@ const ChatInterfaceContent = ({ centerInputOnEmpty }: ChatInterfaceProps) => {
"absolute mx-auto duration-500 ease-in-out",
hasMessages && "inset-x-0 bottom-0 max-w-4xl px-6 pb-6",
!hasMessages && "inset-x-0 bottom-0 max-w-3xl px-6 pb-6 duration-200",
centerInputOnEmpty && !hasMessages && "bottom-1/2 translate-y-full duration-200",
centerInputOnEmpty &&
!hasMessages &&
"bottom-1/2 translate-y-[calc(100%+1rem)] duration-200",
)}
>
{error && <CollapsibleError error={error} />}
@@ -1,4 +1,4 @@
import { useCallback, useState } from "react"
import { startTransition, useCallback, useState } from "react"
import { useTranslation } from "react-i18next"
import { toast } from "sonner"
@@ -131,7 +131,7 @@ export const ChatMoreDropdown = ({
{sessions.map((session) => (
<DropdownMenuItem
key={session.chatId}
onClick={() => chatActions.switchToChat(session.chatId)}
onClick={() => startTransition(() => chatActions.switchToChat(session.chatId))}
className="group flex h-12 cursor-pointer items-center justify-between rounded-md px-2 py-3"
>
<div className="min-w-0 flex-1">
@@ -175,9 +175,9 @@ export const ChatMoreDropdown = ({
<span>Export Chat</span>
</DropdownMenuItem>
<DropdownMenuSeparator />
{canToggleMode && (
<>
<DropdownMenuSeparator />
<DropdownMenuItem onClick={handleToggleMode}>
<i
className={`mr-2 size-4 ${panelStyle === AIChatPanelStyle.Fixed ? "i-mingcute-rectangle-vertical-line" : "i-mingcute-layout-right-line"}`}
@@ -31,7 +31,7 @@ export const WelcomeScreen = ({ onSend, centerInputOnEmpty }: WelcomeScreenProps
scrollbarClassName="mb-40 mt-12"
flex
>
<div className="flex w-full max-w-2xl flex-1 flex-col justify-center space-y-8 pb-52">
<div className="mx-auto flex w-full flex-1 flex-col justify-center space-y-8 pb-52">
{/* Header Section - Always Present */}
<m.div
initial={{ opacity: 0, y: -20 }}
@@ -66,6 +66,7 @@ export const BLOCK_LABELS = {
referFeed: "Feed",
selectedText: "Text",
fileAttachment: "File",
mainView: "View",
} as const
/**
@@ -1,5 +1,5 @@
import { Spring } from "@follow/components/constants/spring.js"
import { cn } from "@follow/utils"
import { clsx } from "@follow/utils"
import { AnimatePresence, m } from "motion/react"
import type { FC } from "react"
@@ -8,16 +8,15 @@ import {
setAIPanelVisibility,
useAIChatPanelStyle,
useAIPanelVisibility,
useAISettingKey,
} from "~/atoms/settings/ai"
import { AISpline } from "~/modules/ai-chat/components/3d-models/AISpline"
import { AISmartSidebar } from "~/modules/ai-chat/components/layouts/AISmartSidebar"
export interface AISplineButtonProps {
className?: string
}
export const AISplineButton: FC<AISplineButtonProps> = ({ className }) => {
export const AIIndicator: FC = () => {
const panelStyle = useAIChatPanelStyle()
const isVisible = useAIPanelVisibility()
const showSplineButton = useAISettingKey("showSplineButton")
// Only show the spline button when:
// 1. Panel style is floating
@@ -30,7 +29,8 @@ export const AISplineButton: FC<AISplineButtonProps> = ({ className }) => {
return (
<AnimatePresence>
{shouldShow && (
{shouldShow && !showSplineButton && <AISmartSidebar />}
{shouldShow && showSplineButton && (
<m.button
key="ai-spline-button"
initial={{ scale: 0, opacity: 0 }}
@@ -40,15 +40,13 @@ export const AISplineButton: FC<AISplineButtonProps> = ({ className }) => {
whileTap={{ scale: 0.95 }}
transition={Spring.presets.smooth}
onClick={handleClick}
className={cn(
className={clsx(
"fixed bottom-8 right-8 z-40",
"size-16 rounded-2xl",
"backdrop-blur-xl",
"hover:scale-105",
"active:scale-95",
"flex items-center justify-center",
"transition-all duration-300 ease-out",
className,
)}
title="Open AI Chat"
>
@@ -8,7 +8,6 @@ import { defaultUISettings } from "@follow/shared/settings/defaults"
import { cn } from "@follow/utils"
import { Slot } from "@radix-ui/react-slot"
import { debounce } from "es-toolkit/compat"
import { AnimatePresence } from "motion/react"
import type { PropsWithChildren } from "react"
import * as React from "react"
import { useEffect, useRef, useState } from "react"
@@ -22,17 +21,12 @@ import {
useTimelineColumnShow,
useTimelineColumnTempShow,
} from "~/atoms/sidebar"
import { m } from "~/components/common/Motion"
import { FloatingLayerScope } from "~/constants"
import { useFeature } from "~/hooks/biz/useFeature"
import { useNavigateEntry } from "~/hooks/biz/useNavigateEntry"
import { useRouteParams } from "~/hooks/biz/useRouteParams"
import { useBatchUpdateSubscription } from "~/hooks/biz/useSubscriptionActions"
import { useI18n } from "~/hooks/common"
import { NetworkStatusIndicator } from "~/modules/app/NetworkStatusIndicator"
import { COMMAND_ID } from "~/modules/command/commands/id"
import { useCommandBinding } from "~/modules/command/hooks/use-command-binding"
import { useEntryContentScrollToTop } from "~/modules/entry-content/atoms"
import { CornerPlayer } from "~/modules/player/corner-player"
import { SubscriptionColumn } from "~/modules/subscription-column"
import { getSelectedFeedIds, resetSelectedFeedIds } from "~/modules/subscription-column/atom"
@@ -107,11 +101,8 @@ const FeedResponsiveResizerContainer = ({
},
})
const aiEnabled = useFeature("ai")
const feedColumnShow = useTimelineColumnShow()
const feedColumnTempShow = useTimelineColumnTempShow()
const { entryId, isPendingEntry, view: currentView } = useRouteParams()
const navigate = useNavigateEntry()
const t = useI18n()
useEffect(() => {
@@ -175,7 +166,6 @@ const FeedResponsiveResizerContainer = ({
timer = clearTimeout(timer)
}
}, [feedColumnShow])
const isAtTop = !!useEntryContentScrollToTop()
return (
<>
@@ -195,27 +185,6 @@ const FeedResponsiveResizerContainer = ({
}}
>
<Slot className={!feedColumnShow ? "!bg-sidebar" : ""}>{children}</Slot>
{/* Semi-transparent overlay with exit hint when in wide mode with entry selected */}
<AnimatePresence>
{entryId && !isPendingEntry && aiEnabled && !isAtTop && (
<m.div
className="bg-background/80 hover:bg-background/90 center absolute inset-0 z-20 cursor-pointer backdrop-blur-[2px] transition-colors duration-200"
onClick={() => navigate({ entryId: null, view: currentView })}
initial={{ opacity: 0 }}
animate={{ opacity: 1 }}
exit={{ opacity: 0 }}
>
<div className="flex flex-col items-center gap-2 rounded-lg">
<div className="text-text flex items-center gap-2">
<i className="i-mgc-up-cute-re text-lg" />
<span className="text-sm font-medium">{t("entry.exit_detail")}</span>
</div>
<span className="text-text-secondary text-xs">{t("entry.click_to_return")}</span>
</div>
</m.div>
)}
</AnimatePresence>
</div>
<div
@@ -3,7 +3,7 @@ import { PanelSplitter } from "@follow/components/ui/divider/index.js"
import { defaultUISettings } from "@follow/shared/settings/defaults"
import { cn } from "@follow/utils"
import { AnimatePresence } from "motion/react"
import { memo, useCallback, useEffect, useMemo, useRef } from "react"
import { memo, useMemo, useRef } from "react"
import { useResizable } from "react-resizable-layout"
import { useParams } from "react-router"
@@ -11,99 +11,21 @@ import { AIChatPanelStyle, useAIChatPanelStyle } from "~/atoms/settings/ai"
import { getUISettings, setUISetting } from "~/atoms/settings/ui"
import { m } from "~/components/common/Motion"
import { ROUTE_ENTRY_PENDING } from "~/constants"
import { useNavigateEntry } from "~/hooks/biz/useNavigateEntry"
import { useRouteParams } from "~/hooks/biz/useRouteParams"
import { AIChatLayout } from "~/modules/app-layout/ai/AIChatLayout"
import { EntryContent } from "~/modules/entry-content/components/entry-content"
import { AppLayoutGridContainerProvider } from "~/providers/app-grid-layout-container-provider"
import { AIChatRoot } from "../ai-chat/components/layouts/AIChatRoot"
import { AISplineButton } from "../app-layout/ai/AISplineButton"
import { setScrollToExitTutorialSeen } from "./atoms/tutorial"
import { AIIndicator } from "../app-layout/ai/AISplineButton"
import { EntryColumn } from "./index"
const AIEntryLayoutImpl = () => {
const { entryId } = useParams()
const navigate = useNavigateEntry()
const panelStyle = useAIChatPanelStyle()
const realEntryId = entryId === ROUTE_ENTRY_PENDING ? "" : entryId
// Swipe/scroll to close functionality
const entryContentRef = useRef<HTMLDivElement>(null)
const accumulatedDelta = useRef(0)
const isScrollingAtTop = useRef(false)
const { view: currentView } = useRouteParams()
const closeEntry = useCallback(() => {
navigate({ entryId: null, view: currentView })
}, [navigate, currentView])
const handleCloseGesture = useCallback(() => {
closeEntry()
}, [closeEntry])
const handleWheel = useCallback(
(e: WheelEvent) => {
if (!realEntryId || !entryContentRef.current) return
// Find the actual scroll viewport element with correct Radix UI attribute
const entryContentElement = entryContentRef.current.querySelector(
"[data-radix-scroll-area-viewport]",
) as HTMLElement
const scrollElement = entryContentElement || entryContentRef.current
// Check if we're at the top of the content
const scrollTop = scrollElement?.scrollTop || 0
isScrollingAtTop.current = scrollTop === 0
// Handle trackpad/mouse wheel: upward scroll (deltaY < 0) or downward swipe gesture
// On macOS trackpad, natural scrolling makes upward finger movement negative deltaY
if (e.deltaY < 0 && isScrollingAtTop.current) {
e.preventDefault()
accumulatedDelta.current += Math.abs(e.deltaY)
// Close when accumulated scroll exceeds threshold (150px for trackpad sensitivity)
if (accumulatedDelta.current > 1000) {
handleCloseGesture()
accumulatedDelta.current = 0
setScrollToExitTutorialSeen(true)
}
} else {
// Reset accumulation when scrolling down or not at top
accumulatedDelta.current = 0
}
},
[realEntryId, handleCloseGesture],
)
useEffect(() => {
if (!realEntryId || !entryContentRef.current) return
const element = entryContentRef.current
// Find the scroll area viewport element with correct Radix UI attribute
const scrollViewport = element.querySelector("[data-radix-scroll-area-viewport]") as HTMLElement
// Add wheel event listener to both the main container and scroll viewport
// This ensures the gesture works in both header area and scrollable content
const elementsToListen: HTMLElement[] = [element]
if (scrollViewport) {
elementsToListen.push(scrollViewport)
}
elementsToListen.forEach((el) => {
el.addEventListener("wheel", handleWheel, { passive: false })
})
return () => {
elementsToListen.forEach((el) => {
el.removeEventListener("wheel", handleWheel)
})
}
}, [realEntryId, handleWheel])
// AI chat resizable panel configuration
const aiColWidth = useMemo(() => getUISettings().aiColWidth, [])
const startDragPosition = useRef(0)
@@ -131,14 +53,14 @@ const AIEntryLayoutImpl = () => {
{/* Entry list - always rendered to prevent animation */}
<EntryColumn key="entry-list" />
<AnimatePresence>
{/* Entry content overlay with exit animation */}
<AnimatePresence mode="popLayout">
{realEntryId && (
<m.div
lcpOptimization
ref={entryContentRef}
initial={{ y: "100%" }}
animate={{ y: 0 }}
exit={{ y: "100%" }}
initial={{ y: 150, opacity: 0, scale: 0.98 }}
animate={{ y: 0, opacity: 1, scale: 1 }}
exit={{ y: 150, opacity: 0, scale: 0.98 }}
transition={Spring.presets.smooth}
className="bg-theme-background absolute inset-0 z-10 border-l"
>
@@ -181,7 +103,7 @@ export const AIEntryLayout = memo(function AIEntryLayout() {
return (
<AIChatRoot wrapFocusable={false}>
<AIEntryLayoutImpl />
<AISplineButton />
<AIIndicator />
</AIChatRoot>
)
})
@@ -1,5 +1,6 @@
import { useGlobalFocusableScopeSelector } from "@follow/components/common/Focusable/hooks.js"
import { ActionButton, Button } from "@follow/components/ui/button/index.js"
import { ActionButton } from "@follow/components/ui/button/index.js"
import { styledButtonVariant } from "@follow/components/ui/button/variants.js"
import { Kbd, KbdCombined } from "@follow/components/ui/kbd/Kbd.js"
import { useCountdown } from "@follow/hooks"
import { EventBus } from "@follow/utils/event-bus"
@@ -138,28 +139,18 @@ export const FlatMarkAllReadButton: FC<
const { className, filter, which, buttonClassName, iconClassName } = props
const [status, setStatus] = useState<"initial" | "confirm" | "done">("initial")
const animate = {
initial: { rotate: -30, opacity: 0.9 },
exit: { rotate: -30, opacity: 0.9 },
animate: { rotate: 0, opacity: 1 },
}
return (
<Button
variant="ghost"
<button
type="button"
disabled={status === "done"}
buttonClassName={buttonClassName}
textClassName={cn(
"center relative flex h-auto gap-1",
className,
)}
className={cn(styledButtonVariant({ variant: "ghost" }), className, buttonClassName)}
onClick={() => {
markAllByRoute(getRouteParams(), filter)
.then(() => setStatus("done"))
.catch(() => setStatus("initial"))
}}
>
<i key={2} {...animate} className={cn("i-mgc-check-circle-cute-re", iconClassName)} />
<i key={2} className={cn("i-mgc-check-circle-cute-re", iconClassName)} />
<span className="duration-200">
{status === "done" ? (
t("mark_all_read_button.done")
@@ -174,6 +165,6 @@ export const FlatMarkAllReadButton: FC<
/>
)}
</span>
</Button>
</button>
)
}
@@ -0,0 +1,100 @@
import { useScrollViewElement } from "@follow/components/ui/scroll-area/hooks.js"
import { throttle } from "es-toolkit"
import { useEffect, useRef, useState } from "react"
import { useEventCallback } from "usehooks-ts"
interface UseWheelGestureCloseOptions {
/** Whether the gesture is enabled */
enabled: boolean
/** Callback to execute when close gesture is triggered */
onClose: () => void
}
interface UseWheelGestureCloseReturn {
/** Whether to show scroll hint indicator */
showScrollHint: boolean
}
/**
* Custom hook for handling wheel gesture to close entry
* Handles trackpad/mouse wheel upward scroll when at top of content
*/
export const useWheelGestureClose = ({
enabled,
onClose: handleCloseGesture,
}: UseWheelGestureCloseOptions): UseWheelGestureCloseReturn => {
const $scrollAreaElement = useScrollViewElement()
const accumulatedDelta = useRef(0)
const isScrollingAtTop = useRef(false)
const [showScrollHint, setShowScrollHint] = useState(false)
const handleWheel = useEventCallback(
throttle((e: WheelEvent) => {
if (!enabled) return
// Find the actual scroll viewport element with correct Radix UI attribute
const scrollElement = $scrollAreaElement
// Check if we're at the top of the content
const scrollTop = scrollElement?.scrollTop || 0
isScrollingAtTop.current = scrollTop === 0
setShowScrollHint(scrollTop === 0)
// Handle trackpad/mouse wheel: upward scroll (deltaY < 0) or downward swipe gesture
// On macOS trackpad, natural scrolling makes upward finger movement negative deltaY
if (e.deltaY < 0 && isScrollingAtTop.current) {
e.preventDefault()
accumulatedDelta.current += Math.abs(e.deltaY)
// Close when accumulated scroll exceeds threshold (150px for trackpad sensitivity)
if (accumulatedDelta.current > 1000) {
handleCloseGesture()
accumulatedDelta.current = 0
}
} else {
// Reset accumulation when scrolling down or not at top
accumulatedDelta.current = 0
}
}, 16),
)
useEffect(() => {
if (!$scrollAreaElement) return
// Find the scroll area viewport element with correct Radix UI attribute
// Add wheel event listener to both the main container and scroll viewport
// This ensures the gesture works in both header area and scrollable content
const elementsToListen: HTMLElement[] = [$scrollAreaElement]
elementsToListen.forEach((el) => {
el.addEventListener("wheel", handleWheel, { passive: false })
})
// Initial scroll position check for hint visibility
const initialCheckScrollPosition = () => {
if (!$scrollAreaElement) return
const scrollTop = $scrollAreaElement.scrollTop || 0
setShowScrollHint(scrollTop === 0)
}
// Check initial position
initialCheckScrollPosition()
// Add scroll listener for hint visibility
$scrollAreaElement.addEventListener("scroll", initialCheckScrollPosition, { passive: true })
return () => {
elementsToListen.forEach((el) => {
el.removeEventListener("wheel", handleWheel)
})
$scrollAreaElement.removeEventListener("scroll", initialCheckScrollPosition)
}
}, [$scrollAreaElement, handleWheel])
return {
showScrollHint,
}
}
@@ -80,7 +80,7 @@ export const EntryListHeader: FC<{
return (
<div
className={cn(
"flex w-full flex-col pr-4 pt-2.5",
"flex h-12 w-full flex-col pr-4 pt-2.5",
!feedColumnShow && "macos:mt-4 macos:pt-margin-macos-traffic-light-y",
titleStyleBasedView[view],
isPreview && "px-4",
@@ -91,7 +91,7 @@ export const EntryListHeader: FC<{
{!isPreview && (
<div
className={cn(
"text-text-secondary relative z-[1] flex items-center gap-1 self-baseline",
"text-text-secondary relative z-[1] flex items-center gap-2 self-baseline",
!headerTitle && "opacity-0 [&_*]:!pointer-events-none",
"translate-x-[6px]",
@@ -74,7 +74,7 @@ export const MoreActions = ({
<DropdownMenu>
<DropdownMenuTrigger asChild>
<ActionButton
icon={<i className="i-mgc-more-1-cute-re" />}
icon={<i className="i-mingcute-more-1-fill" />}
size={compact ? "xs" : "base"}
/>
</DropdownMenuTrigger>
@@ -7,8 +7,12 @@ import { createAtomHooks } from "~/lib/jotai"
export const [, , useEntryTitleMeta, , getEntryTitleMeta, setEntryTitleMeta] = createAtomHooks(
atom(
null as Nullable<{
title: string
description: string
entryTitle: string
feedTitle: string
// id-set
feedId: string
entryId: string
}>,
),
)
@@ -1,8 +1,7 @@
import { useEntry, useEntryReadHistory } from "@follow/store/entry/hooks"
import { useEntry } from "@follow/store/entry/hooks"
import { useFeedById } from "@follow/store/feed/hooks"
import { useInboxById } from "@follow/store/inbox/hooks"
import { useEntryTranslation } from "@follow/store/translation/hooks"
import { useWhoami } from "@follow/store/user/hooks"
import { formatEstimatedMins, formatTimeToSeconds } from "@follow/utils"
import { titleCase } from "title-case"
import { useShallow } from "zustand/shallow"
@@ -11,6 +10,7 @@ import { useShowAITranslation } from "~/atoms/ai-translation"
import { useActionLanguage } from "~/atoms/settings/general"
import { useUISettingKey } from "~/atoms/settings/ui"
import { RelativeTime } from "~/components/ui/datetime"
import { useFeature } from "~/hooks/biz/useFeature"
import { useNavigateEntry } from "~/hooks/biz/useNavigateEntry"
import { useFeedSafeUrl } from "~/hooks/common/useFeedSafeUrl"
import type { FeedIconEntry } from "~/modules/feed/feed-icon"
@@ -18,6 +18,7 @@ import { FeedIcon } from "~/modules/feed/feed-icon"
import { getPreferredTitle } from "~/store/feed/hooks"
import { EntryTranslation } from "../../entry-column/translation"
import { EntryReadHistory } from "./entry-read-history"
interface EntryLinkProps {
entryId: string
@@ -25,7 +26,6 @@ interface EntryLinkProps {
}
export const EntryTitle = ({ entryId, compact }: EntryLinkProps) => {
const user = useWhoami()
const entry = useEntry(
entryId,
useShallow((state) => {
@@ -58,10 +58,11 @@ export const EntryTitle = ({ entryId, compact }: EntryLinkProps) => {
}),
)
const aiEnabled = useFeature("ai")
const hideRecentReader = useUISettingKey("hideRecentReader")
const feed = useFeedById(entry?.feedId)
const inbox = useInboxById(entry?.inboxId)
const data = useEntryReadHistory(entryId)
const entryHistory = data?.entryReadHistories
const populatedFullHref = useFeedSafeUrl(entryId)
const enableTranslation = useShowAITranslation()
const actionLanguage = useActionLanguage()
@@ -75,8 +76,6 @@ export const EntryTitle = ({ entryId, compact }: EntryLinkProps) => {
const navigateEntry = useNavigateEntry()
const hideRecentReader = useUISettingKey("hideRecentReader")
if (!entry) return null
return compact ? (
@@ -94,6 +93,16 @@ export const EntryTitle = ({ entryId, compact }: EntryLinkProps) => {
) : (
<div className="group relative block min-w-0 rounded-lg">
<div className="flex flex-col gap-3">
{/* Recent Readers */}
{aiEnabled &&
(hideRecentReader ? (
<div className="h-8" />
) : (
<div className="-mb-2 mt-2 flex h-8 items-center">
<EntryReadHistory entryId={entryId} />
</div>
))}
<a
href={populatedFullHref ?? "#"}
target="_blank"
@@ -155,19 +164,6 @@ export const EntryTitle = ({ entryId, compact }: EntryLinkProps) => {
<span className="text-xs tabular-nums">{entry.estimatedMins}</span>
</div>
)}
{(() => {
const readCount =
(entryHistory?.readCount ?? 0) +
(entryHistory?.userIds?.every((id) => id !== user?.id) ? 1 : 0)
return readCount > 0 && !hideRecentReader ? (
<div className="flex items-center gap-1.5">
<i className="i-mgc-eye-2-cute-re text-base" />
<span className="text-xs tabular-nums">{readCount.toLocaleString()}</span>
</div>
) : null
})()}
</div>
</div>
</div>
@@ -30,6 +30,7 @@ import { BlockSliceAction } from "~/modules/ai-chat/store/slices/block.slice"
import { COMMAND_ID } from "~/modules/command/commands/id"
import { ApplyEntryActions } from "../../ApplyEntryActions"
import { setEntryContentScrollToTop } from "../../atoms"
import { useEntryContent } from "../../hooks"
import { AIEntryHeader } from "../entry-header"
import { getEntryContentLayout } from "../layouts"
@@ -69,7 +70,7 @@ const EntryContentImpl: Component<EntryContentProps> = ({
const { error, content, isPending } = useEntryContent(entryId)
const view = useRouteParamsSelector((route) => route.view)
const scrollerRef = useRef<HTMLDivElement | null>(null)
const [scrollerRef, setScrollerRef] = useState<HTMLDivElement | null>(null)
const safeUrl = useFeedSafeUrl(entryId)
const isZenMode = useIsZenMode()
@@ -107,6 +108,24 @@ const EntryContentImpl: Component<EntryContentProps> = ({
}
}, [animationController, entryId])
useEffect(() => {
setEntryContentScrollToTop(true)
}, [entryId])
useEffect(() => {
if (!scrollerRef) return
const handler = () => {
setEntryContentScrollToTop(scrollerRef.scrollTop < 50)
}
scrollerRef.addEventListener("scroll", handler)
return () => {
scrollerRef.removeEventListener("scroll", handler)
}
}, [scrollerRef])
const scrollerRefObject = React.useMemo(() => ({ current: scrollerRef }), [scrollerRef])
return (
<div className={cn(className, "@container flex flex-col")}>
<EntryCommandShortcutRegister entryId={entryId} view={view} />
@@ -124,13 +143,13 @@ const EntryContentImpl: Component<EntryContentProps> = ({
>
<RootPortal to={panelPortalElement}>
<EntryScrollingAndNavigationHandler
entryId={entryId}
scrollAnimationRef={scrollAnimationRef}
scrollerRef={scrollerRef}
scrollerRef={scrollerRefObject}
/>
</RootPortal>
{/* <EntryTimeline entryId={entryId} className="top-48" /> */}
<EntryScrollArea scrollerRef={scrollerRef} viewportClassName="pt-[95px]">
<EntryScrollArea scrollerRef={setScrollerRef}>
{/* <EntryNavigationHandler entryId={entryId} /> */}
{/* Indicator for the entry */}
{!isZenMode && isInHasTimelineView && (
<>
@@ -168,7 +187,7 @@ const EntryContentImpl: Component<EntryContentProps> = ({
<article
data-testid="entry-render"
onContextMenu={stopPropagation}
className={"relative w-full min-w-0 pb-10 pt-2"}
className={"relative w-full min-w-0 pb-10 pt-12"}
>
<ApplyEntryActions entryId={entryId} key={entryId} />
@@ -209,7 +228,7 @@ const EntryContentImpl: Component<EntryContentProps> = ({
export const EntryContent = memo(EntryContentImpl)
const EntryScrollArea: Component<{
scrollerRef: React.RefObject<HTMLDivElement | null>
scrollerRef: React.Ref<HTMLDivElement | null>
viewportClassName?: string
}> = ({ children, className, scrollerRef, viewportClassName }) => {
const isInPeekModal = useInPeekModal()
@@ -1,3 +1,4 @@
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"
@@ -15,17 +16,18 @@ 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 { m, useAnimationControls } 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 { useIsZenMode, useUISettingKey } from "~/atoms/settings/ui"
import { Focusable } from "~/components/common/Focusable"
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"
@@ -35,7 +37,9 @@ import { WrappedElementProvider } from "~/providers/wrapped-element-provider"
import { AISummary } from "../../AISummary"
import { ApplyEntryActions } from "../../ApplyEntryActions"
import { NAVIGATION_HINTS_ICONS, NAVIGATION_HINTS_TEXT } from "../../constants/navigation-hints"
import { useEntryContent, useEntryMediaInfo } from "../../hooks"
import { useEntryNavigationHints } from "../../hooks/useEntryNavigationHints"
import { EntryHeader } from "../entry-header"
import { EntryAttachments } from "../EntryAttachments"
import { EntryTimelineSidebar } from "../EntryTimelineSidebar"
@@ -134,11 +138,11 @@ const EntryContentImpl: Component<EntryContentProps> = ({
<EntryScrollingAndNavigationHandler
scrollAnimationRef={scrollAnimationRef}
scrollerRef={scrollerRef}
entryId={entryId}
/>
</RootPortal>
<EntryTimelineSidebar entryId={entryId} />
<EntryScrollArea className={className} scrollerRef={scrollerRef}>
<EntryNavigationHandler entryId={entryId} />
{/* Indicator for the entry */}
<m.div
initial={pageMotionVariants.initial}
@@ -312,3 +316,73 @@ const Renderer: React.FC<{
</EntryContentHTMLRenderer>
)
})
// 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") => (
<m.div
initial={{ y: position === "top" ? -50 : 50, opacity: 0 }}
animate={{ y: 0, opacity: 1 }}
exit={{ y: position === "top" ? -50 : 50, opacity: 0 }}
transition={Spring.presets.smooth}
className={clsx(
"pointer-events-none absolute z-40 flex justify-center",
position === "top" ? "inset-x-0 top-4" : "inset-x-0 bottom-4",
)}
>
<button
onClick={handleCloseEntry}
type="button"
className={clsx(
"group pointer-events-auto flex items-center gap-2",
"rounded-full border px-3.5 py-2",
"border-border/40 bg-material-ultra-thin/70 shadow-[0_1px_2px_rgba(0,0,0,0.06),0_8px_24px_rgba(0,0,0,0.08)]",
"hover:bg-material-thin/70 hover:border-border/60 active:scale-[0.98]",
"backdrop-blur-background",
)}
>
<i className={clsx(icon, "text-text/90 mr-1 size-5")} />
<span className="text-text/90 text-left text-[13px] font-medium">{text}</span>
</button>
</m.div>
)
return (
<AnimatePresence mode="popLayout">
{/* 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")}
</AnimatePresence>
)
}
@@ -16,16 +16,13 @@ import { useEventCallback } from "usehooks-ts"
import { FocusablePresets } from "~/components/common/Focusable"
import { COMMAND_ID } from "~/modules/command/commands/id"
import { useCommandBinding } from "~/modules/command/hooks/use-command-binding"
import { ScrollToExitTutorial } from "~/modules/entry-column/components/ScrollToExitTutorial"
export const EntryScrollingAndNavigationHandler = ({
scrollerRef,
scrollAnimationRef,
entryId,
}: {
scrollerRef: React.RefObject<HTMLDivElement | null>
scrollAnimationRef: React.RefObject<JSAnimation<any> | null>
entryId: string
}) => {
const isAlreadyScrolledBottomRef = useRef(false)
const [showKeepScrollingPanel, setShowKeepScrollingPanel] = useState(false)
@@ -79,20 +76,11 @@ export const EntryScrollingAndNavigationHandler = ({
}
}
const checkScrollBottomByWheel = () => {
isAlreadyScrolledBottomRef.current = false
setShowKeepScrollingPanel(false)
}
scrollerRef.current?.addEventListener("wheel", checkScrollBottomByWheel)
const cleanupScrollAnimation = () => {
scrollAnimationRef.current?.stop()
scrollAnimationRef.current = null
}
return combineCleanupFunctions(
() => {
scrollerRef.current?.removeEventListener("wheel", checkScrollBottomByWheel)
},
cleanupScrollAnimation,
EventBus.subscribe(COMMAND_ID.entryRender.scrollUp, () => {
const $scroller = scrollerRef.current
@@ -175,9 +163,6 @@ export const EntryScrollingAndNavigationHandler = ({
</button>
</m.div>
)}
{/* First-time user tutorial for scroll-to-exit */}
{!!entryId && <ScrollToExitTutorial />}
</AnimatePresence>
)
}
@@ -1,11 +1,9 @@
import { useEntry } from "@follow/store/entry/hooks"
import { useFeedById } from "@follow/store/feed/hooks"
import { useInboxById } from "@follow/store/inbox/hooks"
import { useEffect, useLayoutEffect } from "react"
import { useEffect } from "react"
import { useIsSoFWrappedElement } from "~/providers/wrapped-element-provider"
import { setEntryContentScrollToTop, setEntryTitleMeta } from "../../atoms"
import { setEntryTitleMeta } from "../../atoms"
export const EntryTitleMetaHandler: Component<{
entryId: string
@@ -20,21 +18,14 @@ export const EntryTitleMetaHandler: Component<{
const feed = useFeedById(entry?.feedId)
const inbox = useInboxById(entry?.inboxId)
const feedTitle = feed?.title || inbox?.title
const atTop = useIsSoFWrappedElement()
useEffect(() => {
setEntryContentScrollToTop(true)
}, [entryId])
useLayoutEffect(() => {
setEntryContentScrollToTop(atTop)
}, [atTop])
useEffect(() => {
if (entry?.title && feedTitle) {
setEntryTitleMeta({ title: entry.title, description: feedTitle })
setEntryTitleMeta({ entryTitle: entry.title, feedTitle, feedId: entry.feedId!, entryId })
}
return () => {
setEntryTitleMeta(null)
}
}, [entryId, entry?.title, feedTitle])
}, [entryId, entry?.title, feedTitle, entry?.feedId])
return null
}
@@ -1,69 +1,24 @@
import { Button } from "@follow/components/ui/button/index.js"
import { cn } from "@follow/utils"
import { memo } from "react"
import { useTranslation } from "react-i18next"
import { m } from "~/components/common/Motion"
import { useNavigateEntry } from "~/hooks/biz/useNavigateEntry"
import { useEntryContentScrollToTop } from "~/modules/entry-content/atoms"
import { useEntryContentScrollToTop } from "../../atoms"
import { EntryHeaderRoot } from "./internal/context"
import { EntryHeaderActionsContainer } from "./internal/EntryHeaderActionsContainer"
import { EntryHeaderMeta } from "./internal/EntryHeaderMeta"
import { EntryHeaderReadHistory } from "./internal/EntryHeaderReadHistory"
import { EntryHeaderBreadcrumb } from "./internal/EntryHeaderBreadcrumb"
import type { EntryHeaderProps } from "./types"
function EntryHeaderImpl({ entryId, className, compact }: EntryHeaderProps) {
const { t } = useTranslation()
const navigate = useNavigateEntry()
const isAtTop = useEntryContentScrollToTop()
return (
<>
<EntryHeaderRoot
entryId={entryId}
className={cn(
className,
"@container bg-background z-10 h-[95px] shrink-0 flex-col gap-0 px-3",
)}
compact={compact}
style={{
y: isAtTop ? 0 : -40,
}}
<EntryHeaderRoot entryId={entryId} className={className} compact={compact}>
<div
className="bg-background border-border relative z-10 flex h-12 w-full items-center justify-between gap-3 px-4 data-[at-top='false']:border-b"
data-at-top={isAtTop}
data-hide-in-print
>
{/* Scroll to exit hint - integrated into header to maintain consistent height */}
<m.div
className="z-50 flex h-10 items-center justify-center"
style={{
opacity: isAtTop ? 1 : 0,
}}
>
<Button
variant="ghost"
size="sm"
onClick={() => navigate({ entryId: null })}
buttonClassName="h-full cursor-pointer select-none no-drag-region rounded-none px-6"
aria-label="Scroll up or click to exit"
>
<div className="text-text flex items-center gap-2 rounded-full font-medium">
<i className="i-mgc-up-cute-re repeat-[2] text-base" />
<span>{t("entry.scroll_up_to_exit")}</span>
</div>
</Button>
</m.div>
<div className={cn("center relative h-[55px] w-full")}>
<EntryHeaderReadHistory className="left-0" />
<div
className={cn("relative z-10 flex w-full items-center justify-between gap-3")}
data-hide-in-print
>
<EntryHeaderMeta />
<EntryHeaderActionsContainer />
</div>
</div>
</EntryHeaderRoot>
</>
<EntryHeaderBreadcrumb />
<EntryHeaderActionsContainer />
</div>
</EntryHeaderRoot>
)
}
@@ -3,5 +3,4 @@ export * from "./EntryHeader"
export * from "./internal/context"
export * from "./internal/EntryHeaderActionsContainer"
export * from "./internal/EntryHeaderMeta"
export * from "./internal/EntryHeaderReadHistory"
export * from "./types"
@@ -0,0 +1,294 @@
import { ScrollArea } from "@follow/components/ui/scroll-area/index.js"
import { views } from "@follow/constants"
import { getEntry, getEntryIdsByFeedId } from "@follow/store/entry/getter"
import { useFeedById } from "@follow/store/feed/hooks"
import { useListById } from "@follow/store/list/hooks"
import {
getFeedSubscriptionByViewSelector,
getListSubscriptionByViewSelector,
} from "@follow/store/subscription/getter"
import type {
useFeedSubscriptionByView,
useListSubscriptionByView,
} from "@follow/store/subscription/hooks"
import { useSubscriptionStore } from "@follow/store/subscription/store"
import { cn } from "@follow/utils/utils"
import { useForceUpdate } from "motion/react"
import { useCallback, useRef } from "react"
import { useTranslation } from "react-i18next"
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuTrigger,
} from "~/components/ui/dropdown-menu/dropdown-menu"
import { useNavigateEntry } from "~/hooks/biz/useNavigateEntry"
import { getRouteParams, useRouteParamsSelector } from "~/hooks/biz/useRouteParams"
import { getPreferredTitle } from "~/store/feed/hooks"
import { useEntryTitleMeta } from "../../../atoms"
import { useEntryHeaderContext } from "./context"
const Slash = (
<i className="i-mingcute-line-line text-text-tertiary size-4 shrink-0 rotate-[-25deg]" />
)
function ViewSubscriptionsDropdown({
view,
onNavigate,
}: {
view: number
onNavigate: ReturnType<typeof useNavigateEntry>
}) {
const feedSubsRef = useRef<ReturnType<typeof useFeedSubscriptionByView>>([])
const listSubsRef = useRef<ReturnType<typeof useListSubscriptionByView>>([])
const [forceUpdate] = useForceUpdate()
const handleRefreshDropDownData = useCallback(
(open: boolean) => {
if (!open) return
// Get fresh data from store
const state = useSubscriptionStore.getState()
const feedSubs = getFeedSubscriptionByViewSelector(state)(view)
const listSubs = getListSubscriptionByViewSelector(state)(view)
feedSubsRef.current = feedSubs || []
listSubsRef.current = listSubs || []
forceUpdate()
},
[view, forceUpdate],
)
const routeParams = getRouteParams()
const { isAllFeeds, listId, feedId } = routeParams
// Check if there's any subscription data for this view (without causing re-render)
// This allows initial render to show the dropdown if subscriptions exist
const state = useSubscriptionStore.getState()
const initialFeedSubs = getFeedSubscriptionByViewSelector(state)(view)
const initialListSubs = getListSubscriptionByViewSelector(state)(view)
const hasAnyInitial = (initialFeedSubs?.length ?? 0) + (initialListSubs?.length ?? 0) > 0
if (!hasAnyInitial) return null
return (
<DropdownMenu onOpenChange={handleRefreshDropDownData}>
<DropdownMenuTrigger asChild>
<button
type="button"
className="text-text-tertiary hover:text-text focus-visible:bg-fill/60 -ml-1 inline-flex size-6 items-center justify-center rounded transition-colors"
aria-label="Open subscriptions of this view"
>
<i className="i-mingcute-down-line size-4" />
</button>
</DropdownMenuTrigger>
<DropdownMenuContent align="start" className="p-0">
<ScrollArea.ScrollArea
flex
rootClassName="max-h-[60vh] min-h-0 relative min-w-64"
viewportClassName="max-h-[60vh]"
>
<div className="p-1">
<DropdownMenuItem
onClick={() => onNavigate({ entryId: null, view })}
checked={isAllFeeds}
>
<span className="truncate">All</span>
</DropdownMenuItem>
{listSubsRef.current && listSubsRef.current.length > 0 && (
<div className="text-text-tertiary px-2 py-1 text-xs">Lists</div>
)}
{listSubsRef.current?.map((s) =>
s.listId ? (
<DropdownMenuItem
checked={s.listId === listId}
key={`list-${s.listId}`}
onClick={() => s.listId && onNavigate({ entryId: null, listId: s.listId })}
>
<ListNameItem listId={s.listId} />
</DropdownMenuItem>
) : null,
)}
{feedSubsRef.current && feedSubsRef.current.length > 0 && (
<div className="text-text-tertiary px-2 py-1 text-xs">Feeds</div>
)}
{feedSubsRef.current?.map((s) =>
s.feedId ? (
<DropdownMenuItem
checked={s.feedId === feedId}
key={`feed-${s.feedId}`}
onClick={() => s.feedId && onNavigate({ entryId: null, feedId: s.feedId })}
>
<FeedNameItem feedId={s.feedId} />
</DropdownMenuItem>
) : null,
)}
</div>
</ScrollArea.ScrollArea>
</DropdownMenuContent>
</DropdownMenu>
)
}
const ListNameItem = ({ listId }: { listId: string }) => {
const name = useListById(listId, (s) => s?.title)
if (!name) return null
return <span className="truncate">{name}</span>
}
const FeedNameItem = ({ feedId }: { feedId: string }) => {
const feed = useFeedById(feedId)
if (!feed) return null
return <span className="truncate">{getPreferredTitle(feed)}</span>
}
function FeedEntriesDropdown({
feedId,
currentEntryId,
onNavigate,
}: {
feedId: string
currentEntryId: string
onNavigate: ReturnType<typeof useNavigateEntry>
}) {
const siblingEntriesRef = useRef<{ id: string; title: string }[]>([])
const [forceUpdate] = useForceUpdate()
const handleRefreshDropDownData = useCallback(
(open: boolean) => {
if (!open) return
const entryIds = getEntryIdsByFeedId(feedId)
if (!entryIds) return
siblingEntriesRef.current = []
for (const entryId of entryIds) {
const entry = getEntry(entryId)
if (!entry) continue
const { title } = entry
if (!title) continue
siblingEntriesRef.current.push({ id: entryId, title })
}
forceUpdate()
},
[feedId, forceUpdate],
)
// Check if there are any entries for this feed
const entryIds = getEntryIdsByFeedId(feedId)
if (!entryIds || entryIds.length <= 1) return null
return (
<DropdownMenu onOpenChange={handleRefreshDropDownData}>
<DropdownMenuTrigger asChild>
<button
type="button"
className="text-text-tertiary hover:text-text focus-visible:bg-fill/60 -ml-2 inline-flex size-6 items-center justify-center rounded transition-colors"
aria-label="Open entries from this feed"
>
<i className="i-mingcute-down-line size-4" />
</button>
</DropdownMenuTrigger>
<DropdownMenuContent align="start" className="p-0">
<ScrollArea.ScrollArea
rootClassName="max-h-[60vh] min-w-64"
viewportClassName="max-h-[60vh]"
>
<div className="p-1">
{siblingEntriesRef.current.map((e) => (
<DropdownMenuItem
key={e.id}
onClick={() => onNavigate({ entryId: e.id })}
checked={e.id === currentEntryId}
>
<span className="truncate" title={e.title}>
{e.title}
</span>
</DropdownMenuItem>
))}
</div>
</ScrollArea.ScrollArea>
</DropdownMenuContent>
</DropdownMenu>
)
}
export function EntryHeaderBreadcrumb() {
const meta = useEntryTitleMeta()
const navigate = useNavigateEntry()
const { entryId } = useEntryHeaderContext()
const { t } = useTranslation()
const view = useRouteParamsSelector((s) => s.view)
if (!meta) return null
return (
<div className="flex min-w-0 flex-1 items-center gap-1 overflow-hidden">
<nav
aria-label="Breadcrumb"
className={
"text-text-secondary group/breadcrumb flex min-w-0 items-center gap-1 truncate leading-tight"
}
>
<div className="flex min-w-0 items-center gap-1">
{/* Return Back Button */}
<button
type="button"
className="text-text-secondary hover:text-text hover:bg-fill/50 focus-visible:bg-fill/60 inline-flex shrink-0 items-center rounded bg-transparent p-2"
onClick={() => navigate({ entryId: null })}
>
<i className="i-mingcute-close-fill size-4" />
</button>
{views[view]?.name && (
<div className="flex items-center">
<button
type="button"
className={cn(
"text-text-secondary hover:text-text hover:bg-fill/50 focus-visible:bg-fill/60 inline-flex max-w-[40vw] items-center truncate rounded bg-transparent px-1.5 py-0.5 text-sm transition-colors",
)}
onClick={() => navigate({ entryId: null, view })}
>
<span className="text-text-secondary text-sm">
{t(views[view]?.name, { ns: "common" })}
</span>
</button>
<ViewSubscriptionsDropdown view={view} onNavigate={navigate} />
</div>
)}
{Slash}
<div className="flex items-center">
<button
type="button"
className={cn(
"text-text-secondary hover:text-text hover:bg-fill/50 focus-visible:bg-fill/60 inline-flex max-w-[40vw] items-center truncate rounded bg-transparent px-1.5 py-0.5 text-sm transition-colors",
)}
onClick={() => navigate({ entryId: null, feedId: meta.feedId })}
title={meta.feedTitle}
>
<span className="truncate">{meta.feedTitle}</span>
</button>
<FeedEntriesDropdown
feedId={meta.feedId}
currentEntryId={entryId}
onNavigate={navigate}
/>
</div>
{Slash}
<span className="text-text truncate px-1.5 py-0.5 text-sm" title={meta.entryTitle}>
{meta.entryTitle}
</span>
</div>
</nav>
</div>
)
}
@@ -6,7 +6,7 @@ import { useEntryContentScrollToTop, useEntryTitleMeta } from "../../../atoms"
function EntryHeaderMetaImpl() {
const entryTitleMeta = useEntryTitleMeta()
const isAtTop = useEntryContentScrollToTop()
const shouldShowMeta = !isAtTop && !!entryTitleMeta?.title
const shouldShowMeta = !isAtTop && !!entryTitleMeta?.entryTitle
return (
<div className="flex min-w-0 shrink grow">
<AnimatePresence>
@@ -17,10 +17,10 @@ function EntryHeaderMetaImpl() {
exit={{ opacity: 0.01, y: 30 }}
className="text-text text-title3 flex min-w-0 flex-1 shrink items-end gap-2 truncate leading-tight"
>
<span className="shrink truncate font-bold">{entryTitleMeta.title}</span>
<span className="shrink truncate font-bold">{entryTitleMeta.entryTitle}</span>
<i className="i-mgc-line-cute-re text-text-secondary size-[10px] shrink-0 translate-y-[-3px] rotate-[-25deg]" />
<span className="text-text-secondary text-headline shrink -translate-y-px truncate">
{entryTitleMeta.description}
{entryTitleMeta.feedTitle}
</span>
</m.div>
)}
@@ -0,0 +1,40 @@
/**
* Constants for entry navigation hints behavior
*/
export const NAVIGATION_HINTS_CONSTANTS = {
/** Default scroll threshold to trigger scroll hint (px) */
DEFAULT_SCROLL_THRESHOLD: 100,
/** Delay before showing first entry hint (ms) */
FIRST_HINT_DELAY: 500,
/** Duration to show hints before auto-hiding (ms) */
HINT_DISPLAY_DURATION: 3000,
/** Distance from bottom to trigger bottom hint (px) */
BOTTOM_THRESHOLD: 50,
/** Distance from bottom to hide bottom hint when scrolling up (px) */
BOTTOM_HIDE_THRESHOLD: 100,
/** Throttle interval for scroll handler (ms) */
SCROLL_THROTTLE_INTERVAL: 100,
} as const
/**
* Text constants for navigation hints
*/
export const NAVIGATION_HINTS_TEXT = {
SCROLL_UP_EXIT: "Scroll up or click left-top back button to exit",
ESC_EXIT: "Press ESC or click left-top back button to exit",
} as const
/**
* Icon constants for navigation hints
*/
export const NAVIGATION_HINTS_ICONS = {
ARROW_UP: "i-mgc-up-cute-re",
ARROW_LEFT_UP: "i-mingcute-arrow-left-up-line",
ARROW_TO_DOWN: "i-mingcute-arrow-to-down-line",
CLOSE: "i-mgc-close-cute-re",
} as const
@@ -0,0 +1,201 @@
import { useScrollViewElement } from "@follow/components/ui/scroll-area/hooks.js"
import { throttle } from "es-toolkit"
import { startTransition, useEffect, useRef, useState } from "react"
import { useEventCallback } from "usehooks-ts"
import { NAVIGATION_HINTS_CONSTANTS } from "../constants/navigation-hints"
interface UseEntryNavigationHintsOptions {
/** Whether hints are enabled */
enabled: boolean
/** Entry ID to track changes */
entryId?: string
/** Scroll threshold to show hint */
scrollThreshold?: number
}
interface UseEntryNavigationHintsReturn {
/** Show hint for first entry */
showFirstEntryHint: boolean
/** Show hint when scrolled past threshold */
showScrollHint: boolean
/** Show hint when at bottom */
showBottomHint: boolean
}
/**
* Custom hook for managing entry navigation hints
* Shows contextual hints based on scroll position and entry state
*/
export const useEntryNavigationHints = ({
enabled,
entryId,
scrollThreshold = NAVIGATION_HINTS_CONSTANTS.DEFAULT_SCROLL_THRESHOLD,
}: UseEntryNavigationHintsOptions): UseEntryNavigationHintsReturn => {
const $scrollElement = useScrollViewElement()
// State for different hint types
const [showFirstEntryHint, setShowFirstEntryHint] = useState(false)
const [showScrollHint, setShowScrollHint] = useState(false)
const [showBottomHint, setShowBottomHint] = useState(false)
// Refs to track state
const hasShownFirstHintRef = useRef(false)
const hasShownScrollHintRef = useRef(false)
const hasShownBottomHintRef = useRef(false)
const currentEntryIdRef = useRef<string>(void 0)
const firstHintTimerRef = useRef<ReturnType<typeof setTimeout>>(void 0)
const scrollHintTimerRef = useRef<ReturnType<typeof setTimeout>>(void 0)
const bottomHintTimerRef = useRef<ReturnType<typeof setTimeout>>(void 0)
const lastScrollTopRef = useRef(0)
const scrollDirectionRef = useRef<"up" | "down" | "none">("none")
// Reset hints when entry changes
useEffect(() => {
if (entryId && entryId !== currentEntryIdRef.current) {
currentEntryIdRef.current = entryId
hasShownFirstHintRef.current = false
hasShownScrollHintRef.current = false
hasShownBottomHintRef.current = false
lastScrollTopRef.current = 0
scrollDirectionRef.current = "none"
// Clear existing timers
if (firstHintTimerRef.current) clearTimeout(firstHintTimerRef.current)
if (scrollHintTimerRef.current) clearTimeout(scrollHintTimerRef.current)
if (bottomHintTimerRef.current) clearTimeout(bottomHintTimerRef.current)
// Reset all hint states with low priority
startTransition(() => {
setShowFirstEntryHint(false)
setShowScrollHint(false)
setShowBottomHint(false)
})
if (enabled) {
// Show first entry hint after a brief delay
firstHintTimerRef.current = setTimeout(() => {
if (!hasShownFirstHintRef.current) {
startTransition(() => {
setShowFirstEntryHint(true)
})
hasShownFirstHintRef.current = true
// Hide after configured duration
firstHintTimerRef.current = setTimeout(() => {
startTransition(() => {
setShowFirstEntryHint(false)
})
}, NAVIGATION_HINTS_CONSTANTS.HINT_DISPLAY_DURATION)
}
}, NAVIGATION_HINTS_CONSTANTS.FIRST_HINT_DELAY) // Small delay to allow content to load
}
}
}, [entryId, enabled])
// Scroll handler to manage hints based on scroll position
const handleScroll = useEventCallback(
throttle(() => {
if (!enabled || !$scrollElement) return
const { scrollTop } = $scrollElement
const { scrollHeight } = $scrollElement
const { clientHeight } = $scrollElement
const scrollBottom = scrollHeight - clientHeight - scrollTop
// Detect scroll direction
const lastScrollTop = lastScrollTopRef.current
if (scrollTop > lastScrollTop) {
scrollDirectionRef.current = "down"
} else if (scrollTop < lastScrollTop) {
scrollDirectionRef.current = "up"
}
lastScrollTopRef.current = scrollTop
// Check if scrolled past threshold and scrolling up
if (
scrollTop > scrollThreshold &&
!hasShownScrollHintRef.current &&
scrollDirectionRef.current === "up"
) {
hasShownScrollHintRef.current = true
startTransition(() => {
setShowScrollHint(true)
})
// Clear previous timer
if (scrollHintTimerRef.current) clearTimeout(scrollHintTimerRef.current)
// Hide after configured duration
scrollHintTimerRef.current = setTimeout(() => {
startTransition(() => {
setShowScrollHint(false)
})
}, NAVIGATION_HINTS_CONSTANTS.HINT_DISPLAY_DURATION)
}
// Check if at bottom (within configured threshold)
if (
scrollBottom <= NAVIGATION_HINTS_CONSTANTS.BOTTOM_THRESHOLD &&
!hasShownBottomHintRef.current
) {
hasShownBottomHintRef.current = true
startTransition(() => {
setShowBottomHint(true)
})
// Clear previous timer
if (bottomHintTimerRef.current) clearTimeout(bottomHintTimerRef.current)
// Hide after configured duration
bottomHintTimerRef.current = setTimeout(() => {
startTransition(() => {
setShowBottomHint(false)
})
hasShownBottomHintRef.current = false
}, NAVIGATION_HINTS_CONSTANTS.HINT_DISPLAY_DURATION)
}
// Hide bottom hint if user scrolls up from bottom
if (
scrollBottom > NAVIGATION_HINTS_CONSTANTS.BOTTOM_HIDE_THRESHOLD &&
hasShownBottomHintRef.current &&
scrollDirectionRef.current === "up"
) {
// Clear timer if exists
if (bottomHintTimerRef.current) clearTimeout(bottomHintTimerRef.current)
startTransition(() => {
setShowBottomHint(false)
})
hasShownBottomHintRef.current = false
}
}, NAVIGATION_HINTS_CONSTANTS.SCROLL_THROTTLE_INTERVAL),
)
// Attach scroll listener
useEffect(() => {
if (!enabled || !$scrollElement) return
$scrollElement.addEventListener("scroll", handleScroll, { passive: true })
return () => {
$scrollElement.removeEventListener("scroll", handleScroll)
}
}, [enabled, $scrollElement, handleScroll])
// Cleanup timers on unmount
useEffect(() => {
return () => {
if (firstHintTimerRef.current) clearTimeout(firstHintTimerRef.current)
if (scrollHintTimerRef.current) clearTimeout(scrollHintTimerRef.current)
if (bottomHintTimerRef.current) clearTimeout(bottomHintTimerRef.current)
}
}, [])
return {
showFirstEntryHint,
showScrollHint,
showBottomHint,
}
}
@@ -30,6 +30,10 @@ export const SettingAI = () => {
},
PanelStyleSection,
defineSettingItem("showSplineButton", {
label: t("settings.showSplineButton.label"),
description: t("settings.showSplineButton.description"),
}),
defineSettingItem("autoScrollWhenStreaming", {
label: t("settings.autoScrollWhenStreaming.label"),
description: t("settings.autoScrollWhenStreaming.description"),
@@ -138,7 +138,7 @@ export function SubscriptionColumn({
</RootPortal>
)}
<div className="relative mb-4 mt-3">
<div className="relative mb-2 mt-3">
<TabsRow />
</div>
<div
@@ -265,7 +265,7 @@ const TabsRow: FC = () => {
}
return (
<div className="text-text-secondary flex h-11 items-center px-3 text-xl">
<div className="text-text-secondary flex h-11 items-center px-1 text-xl">
<SubscriptionTabButton
shortcut="BackQuote"
key={first}
@@ -21,7 +21,7 @@ export const ListHeader = ({ view }: { view: FeedViewType }) => {
const navigateEntry = useNavigateEntry()
return (
<div onClick={stopPropagation} className="mx-3 flex items-center justify-between px-2.5 py-1">
<div onClick={stopPropagation} className="mx-3 flex items-center justify-between p-1">
<div
className="text-base font-bold"
onClick={(e) => {
@@ -244,7 +244,7 @@ const SubscriptionImpl = ({ ref, className, view, isSubscriptionLoading }: Subsc
}}
mask={false}
flex
viewportClassName={cn("!px-3", shouldFreeUpSpace && "!overflow-visible")}
viewportClassName={cn("!px-1", shouldFreeUpSpace && "!overflow-visible")}
rootClassName={cn("h-full", shouldFreeUpSpace && "overflow-visible")}
>
<StarredItem view={view} />
@@ -416,7 +416,7 @@ const useRegisterCommand = () => {
}
const SubscriptionListSkeleton = () => (
<div className="px-3">
<div className="px-1">
{Array.from({ length: 5 }).map((_, index) => (
<div key={index} className="flex h-8 items-center justify-between">
<Skeleton className="h-4 w-28" />
@@ -4,7 +4,10 @@ import { ChatInterface } from "~/modules/ai-chat/components/layouts/ChatInterfac
export const Component = () => {
return (
<div className="relative flex h-screen w-full flex-col">
<div
className="relative flex h-screen w-full flex-col"
style={{ "--ai-chat-layout-width": "65rem" } as React.CSSProperties}
>
<AIChatRoot>
<ChatPageHeader />
<ChatInterface centerInputOnEmpty />
+2
View File
@@ -122,6 +122,8 @@
"settings.panel_style.fixed": "Fixed",
"settings.panel_style.floating": "Floating",
"settings.panel_style.label": "Panel Style",
"settings.showSplineButton.description": "Show or hide the AI assistant indicator in the bottom-right corner",
"settings.showSplineButton.label": "AI Assistant Indicator",
"settings.title": "AI Settings",
"shortcuts.add": "Add Shortcut",
"shortcuts.added": "Shortcut added successfully",
@@ -1,5 +1,4 @@
import type { Transition } from "motion/react"
/**
* A smooth spring with a predefined duration and no bounce.
*/