feat: implement mobile layout for AIEnhancedTimeline
- Added MobileTimelineLayout component to handle mobile-specific rendering. - Integrated useMobile hook for responsive behavior in AIEnhancedTimelineLayout. - Updated layout logic to conditionally render components based on mobile view. - Enhanced dropdown and context menu styles for better visual feedback. Signed-off-by: Innei <tukon479@gmail.com>
This commit is contained in:
@@ -171,7 +171,7 @@ const DropdownMenuItem = ({
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"relative flex cursor-menu select-none items-center rounded-[5px] px-2.5 py-1 outline-none focus:bg-accent/30 data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
|
||||
"focus-within:outline-transparent data-[highlighted]:bg-mix-background/accent-5/1",
|
||||
"focus-within:outline-transparent data-[highlighted]:text-accent data-[highlighted]:bg-mix-background/accent-9/1",
|
||||
"h-[28px]",
|
||||
inset && "pl-8",
|
||||
className,
|
||||
|
||||
+50
-22
@@ -1,4 +1,5 @@
|
||||
import { Spring } from "@follow/components/constants/spring.js"
|
||||
import { useMobile } from "@follow/components/hooks/useMobile.js"
|
||||
import { PanelSplitter } from "@follow/components/ui/divider/index.js"
|
||||
import { FeedViewType } from "@follow/constants"
|
||||
import { defaultUISettings } from "@follow/shared/settings/defaults"
|
||||
@@ -25,6 +26,8 @@ import { AIEntryHeader } from "~/modules/entry-content/components/entry-header"
|
||||
import { AppLayoutGridContainerProvider } from "~/providers/app-grid-layout-container-provider"
|
||||
import { MainViewHotkeysProvider } from "~/providers/main-view-hotkeys-provider"
|
||||
|
||||
import { MobileTimelineLayout } from "./MobileTimelineLayout"
|
||||
|
||||
const MIN_ENTRY_WIDTH = isSafari() ? 356 : 300
|
||||
|
||||
const AIEnhancedTimelineLayoutImpl = () => {
|
||||
@@ -38,6 +41,19 @@ const AIEnhancedTimelineLayoutImpl = () => {
|
||||
const aiPanelStyle = useAIChatPanelStyle()
|
||||
const isAIPanelVisible = useAIPanelVisibility()
|
||||
const hasSelectedEntry = Boolean(realEntryId)
|
||||
const isMobile = useMobile()
|
||||
|
||||
// Compute derived values first
|
||||
const showEntryContentOnRight = showEntryDetailsColumn && hasSelectedEntry
|
||||
const isFixedPanelStyle = aiPanelStyle === AIChatPanelStyle.Fixed
|
||||
const shouldShowFixedAI = isFixedPanelStyle && isAIPanelVisible
|
||||
const showEntryContentOnLeft = !showEntryDetailsColumn && hasSelectedEntry
|
||||
const shouldRenderRightColumn = showEntryDetailsColumn || shouldShowFixedAI
|
||||
const shouldShowEntryBorder = showEntryDetailsColumn || shouldShowFixedAI
|
||||
|
||||
// Mobile-specific logic: disable resizing and hide splitters
|
||||
const shouldDisableResize = isMobile
|
||||
const shouldShowSplitter = !isMobile && shouldRenderRightColumn
|
||||
|
||||
const layoutContainerRef = useRef<HTMLDivElement>(null)
|
||||
const feedColumnWidth = useUISettingKey("feedColWidth")
|
||||
@@ -62,6 +78,7 @@ const AIEnhancedTimelineLayoutImpl = () => {
|
||||
max: timelineMaxWidth,
|
||||
initial: entryColumnInitialWidth,
|
||||
containerRef: layoutContainerRef as React.RefObject<HTMLElement>,
|
||||
disabled: shouldDisableResize,
|
||||
onResizeStart({ position }) {
|
||||
timelineStartDragPosition.current = position
|
||||
},
|
||||
@@ -101,6 +118,7 @@ const AIEnhancedTimelineLayoutImpl = () => {
|
||||
initial: resolvePreferredWidth(),
|
||||
reverse: true,
|
||||
containerRef: layoutContainerRef as React.RefObject<HTMLElement>,
|
||||
disabled: shouldDisableResize,
|
||||
onResizeStart({ position }) {
|
||||
aiPanelStartDragPosition.current = position
|
||||
},
|
||||
@@ -117,32 +135,36 @@ const AIEnhancedTimelineLayoutImpl = () => {
|
||||
window.dispatchEvent(new Event("resize"))
|
||||
}, [resolvePreferredWidth, setAiPanelWidth])
|
||||
|
||||
const showEntryContentOnRight = showEntryDetailsColumn && hasSelectedEntry
|
||||
const isFixedPanelStyle = aiPanelStyle === AIChatPanelStyle.Fixed
|
||||
const shouldShowFixedAI = isFixedPanelStyle && isAIPanelVisible
|
||||
const showEntryContentOnLeft = !showEntryDetailsColumn && hasSelectedEntry
|
||||
|
||||
const shouldRenderRightColumn = showEntryDetailsColumn || shouldShowFixedAI
|
||||
const shouldShowEntryBorder = showEntryDetailsColumn || shouldShowFixedAI
|
||||
|
||||
const entryColumnStyle: CSSProperties = showEntryDetailsColumn
|
||||
const entryColumnStyle: CSSProperties = isMobile
|
||||
? {
|
||||
flexBasis: timelineColumnWidth,
|
||||
minWidth: MIN_ENTRY_WIDTH,
|
||||
}
|
||||
: {
|
||||
minWidth: MIN_ENTRY_WIDTH,
|
||||
width: "100%",
|
||||
minWidth: "100%",
|
||||
flexBasis: "100%",
|
||||
}
|
||||
: showEntryDetailsColumn
|
||||
? {
|
||||
flexBasis: timelineColumnWidth,
|
||||
minWidth: MIN_ENTRY_WIDTH,
|
||||
}
|
||||
: {
|
||||
minWidth: MIN_ENTRY_WIDTH,
|
||||
}
|
||||
|
||||
const rightColumnStyle: CSSProperties = showEntryDetailsColumn
|
||||
const rightColumnStyle: CSSProperties = isMobile
|
||||
? {
|
||||
minWidth: 0,
|
||||
}
|
||||
: {
|
||||
width: aiPanelWidth,
|
||||
minWidth: 0,
|
||||
flexBasis: aiPanelWidth,
|
||||
width: "100%",
|
||||
minWidth: "100%",
|
||||
flexBasis: "100%",
|
||||
}
|
||||
: showEntryDetailsColumn
|
||||
? {
|
||||
minWidth: 0,
|
||||
}
|
||||
: {
|
||||
width: aiPanelWidth,
|
||||
minWidth: 0,
|
||||
flexBasis: aiPanelWidth,
|
||||
}
|
||||
|
||||
const resetTimelineWidth = useCallback(() => {
|
||||
setUISetting("entryColWidth", defaultUISettings.entryColWidth)
|
||||
@@ -157,7 +179,7 @@ const AIEnhancedTimelineLayoutImpl = () => {
|
||||
window.dispatchEvent(new Event("resize"))
|
||||
}, [clampWidth, setAiPanelWidth])
|
||||
|
||||
const splitter =
|
||||
const splitter = shouldShowSplitter ? (
|
||||
shouldRenderRightColumn && showEntryDetailsColumn ? (
|
||||
<PanelSplitter
|
||||
{...timelineSeparatorProps}
|
||||
@@ -173,6 +195,12 @@ const AIEnhancedTimelineLayoutImpl = () => {
|
||||
onDoubleClick={resetAiWidth}
|
||||
/>
|
||||
) : null
|
||||
) : null
|
||||
|
||||
// Mobile layout: stacked with view switching
|
||||
if (isMobile) {
|
||||
return <MobileTimelineLayout entryId={realEntryId} hasSelectedEntry={hasSelectedEntry} />
|
||||
}
|
||||
|
||||
return (
|
||||
<div
|
||||
|
||||
+96
@@ -0,0 +1,96 @@
|
||||
import { Spring } from "@follow/components/constants/spring.js"
|
||||
import { AnimatePresence } from "motion/react"
|
||||
import { memo, useEffect, useState } from "react"
|
||||
|
||||
import { m } from "~/components/common/Motion"
|
||||
import { useNavigateEntry } from "~/hooks/biz/useNavigateEntry"
|
||||
import { useRouteParamsSelector } from "~/hooks/biz/useRouteParams"
|
||||
import { useShowEntryDetailsColumn } from "~/hooks/biz/useShowEntryDetailsColumn"
|
||||
import { EntryColumn } from "~/modules/entry-column"
|
||||
import { EntryContent } from "~/modules/entry-content/components/entry-content"
|
||||
import { AIEntryHeader } from "~/modules/entry-content/components/entry-header"
|
||||
import { AppLayoutGridContainerProvider } from "~/providers/app-grid-layout-container-provider"
|
||||
|
||||
type MobileView = "list" | "entry"
|
||||
|
||||
interface MobileTimelineLayoutProps {
|
||||
entryId: string | undefined
|
||||
hasSelectedEntry: boolean
|
||||
}
|
||||
|
||||
export const MobileTimelineLayout = memo(function MobileTimelineLayout({
|
||||
entryId,
|
||||
hasSelectedEntry,
|
||||
}: MobileTimelineLayoutProps) {
|
||||
const [mobileView, setMobileView] = useState<MobileView>("list")
|
||||
const navigate = useNavigateEntry()
|
||||
const { view } = useRouteParamsSelector((state) => ({
|
||||
view: state.view,
|
||||
}))
|
||||
const showEntryDetailsColumn = useShowEntryDetailsColumn()
|
||||
// Auto-switch to entry view when entry is selected
|
||||
useEffect(() => {
|
||||
if (hasSelectedEntry && mobileView === "list") {
|
||||
setMobileView("entry")
|
||||
} else if (!hasSelectedEntry && mobileView === "entry") {
|
||||
setMobileView("list")
|
||||
}
|
||||
}, [hasSelectedEntry, mobileView])
|
||||
|
||||
return (
|
||||
<div className="relative flex size-full flex-col overflow-hidden">
|
||||
<AppLayoutGridContainerProvider>
|
||||
<div className="relative flex size-full flex-col">
|
||||
{/* List View */}
|
||||
<AnimatePresence mode="wait">
|
||||
{mobileView === "list" && (
|
||||
<m.div
|
||||
key="mobile-list"
|
||||
initial={{ opacity: 0, x: -20 }}
|
||||
animate={{ opacity: 1, x: 0 }}
|
||||
exit={{ opacity: 0, x: -20 }}
|
||||
transition={Spring.smooth(0.2)}
|
||||
className="absolute inset-0 flex size-full flex-col overflow-hidden"
|
||||
>
|
||||
<EntryColumn />
|
||||
</m.div>
|
||||
)}
|
||||
|
||||
{/* Entry View */}
|
||||
{mobileView === "entry" && entryId && (
|
||||
<m.div
|
||||
key="mobile-entry"
|
||||
initial={{ opacity: 0, x: 20 }}
|
||||
animate={{ opacity: 1, x: 0 }}
|
||||
exit={{ opacity: 0, x: 20 }}
|
||||
transition={Spring.smooth(0.2)}
|
||||
className="absolute inset-0 flex size-full flex-col overflow-hidden bg-theme-background"
|
||||
>
|
||||
<div className="flex-shrink-0 bg-background">
|
||||
<div className="flex items-center">
|
||||
{/* Mobile back button - only show when EntryHeaderBreadcrumb doesn't show close button */}
|
||||
{showEntryDetailsColumn && (
|
||||
<button
|
||||
type="button"
|
||||
className="no-drag-region mx-2 inline-flex shrink-0 items-center rounded-full bg-transparent p-2 text-text-secondary hover:bg-fill/50 hover:text-text focus-visible:bg-fill/60"
|
||||
onClick={() => navigate({ entryId: null, view })}
|
||||
>
|
||||
<i className="i-mingcute-close-line size-5" />
|
||||
</button>
|
||||
)}
|
||||
<div className="min-w-0 flex-1 overflow-hidden">
|
||||
<AIEntryHeader entryId={entryId} />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex-1 overflow-hidden">
|
||||
<EntryContent entryId={entryId} className="h-full" />
|
||||
</div>
|
||||
</m.div>
|
||||
)}
|
||||
</AnimatePresence>
|
||||
</div>
|
||||
</AppLayoutGridContainerProvider>
|
||||
</div>
|
||||
)
|
||||
})
|
||||
@@ -36,7 +36,8 @@ const ContextMenuSubTrigger = ({
|
||||
<ContextMenuPrimitive.SubTrigger
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"cursor-menu focus:bg-accent/30 data-[state=open]:bg-accent/30 flex select-none items-center rounded-[5px] px-2.5 py-1.5 outline-none",
|
||||
"cursor-menu data-[state=open]:bg-mix-background/accent-9/1 data-[state=open]:text-accent data-[highlighted]:text-accent data-[highlighted]:bg-mix-background/accent-9/1 flex select-none items-center rounded-[5px] px-2.5 py-1.5 outline-none",
|
||||
"h-[28px]",
|
||||
inset && "pl-8",
|
||||
"center gap-2",
|
||||
className,
|
||||
@@ -129,8 +130,8 @@ const ContextMenuItem = ({
|
||||
<ContextMenuPrimitive.Item
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"cursor-menu focus:bg-accent/30 relative flex select-none items-center rounded-[5px] px-2.5 py-1 outline-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
|
||||
"data-[highlighted]:bg-mix-background/accent-5/1 focus-within:outline-transparent",
|
||||
"cursor-menu focus:bg-accent/30 relative flex select-none items-center rounded-[5px] px-2.5 py-1.5 outline-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
|
||||
"data-[highlighted]:text-accent data-[highlighted]:bg-mix-background/accent-9/1 focus-within:outline-transparent",
|
||||
"h-[28px]",
|
||||
inset && "pl-8",
|
||||
className,
|
||||
@@ -153,7 +154,7 @@ const ContextMenuCheckboxItem = ({
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"cursor-checkbox focus:bg-accent/30 relative flex select-none items-center rounded-[5px] px-8 py-1.5 outline-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
|
||||
"focus-within:outline-transparent",
|
||||
"data-[highlighted]:text-accent data-[highlighted]:bg-mix-background/accent-9/1 focus-within:text-accent focus-within:outline-transparent",
|
||||
"h-[28px]",
|
||||
className,
|
||||
)}
|
||||
|
||||
Reference in New Issue
Block a user