feat: Scroll to top when re-navigating to Discover page while already on it (#2371)

This commit is contained in:
Zeke 2024-12-29 23:36:45 +08:00 committed by GitHub
parent 1bf2e20801
commit a59cf4a4cf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 17 additions and 1 deletions

View File

@ -1,11 +1,12 @@
import { getReadonlyRoute } from "@follow/components/atoms/route.js"
import { MotionButtonBase } from "@follow/components/ui/button/index.js"
import { ScrollArea } from "@follow/components/ui/scroll-area/index.js"
import { Routes } from "@follow/constants"
import { springScrollTo } from "@follow/utils/scroller"
import { cn, getOS } from "@follow/utils/utils"
import { useEffect, useRef, useState } from "react"
import { useTranslation } from "react-i18next"
import { Outlet, useNavigate } from "react-router"
import { NavigationType, Outlet, useLocation, useNavigate, useNavigationType } from "react-router"
import { getSidebarActiveView, setSidebarActiveView } from "~/atoms/sidebar"
import { FABContainer, FABPortable } from "~/components/ui/fab"
@ -20,6 +21,19 @@ export function SubviewLayout() {
const title = useSubViewTitleValue()
const [scrollRef, setRef] = useState(null as HTMLDivElement | null)
const [isTitleSticky, setIsTitleSticky] = useState(false)
const navigationType = useNavigationType()
const location = useLocation()
useEffect(() => {
// Scroll to top search bar when re-navigating to Discover page while already on it
if (
navigationType === NavigationType.Replace &&
location.pathname === Routes.Discover &&
scrollRef
) {
springScrollTo(0, scrollRef)
}
}, [location, navigationType, scrollRef])
useEffect(() => {
const $scroll = scrollRef

View File

@ -2,6 +2,8 @@
## New Features
- Scroll to top when re-navigating to Discover page while already on it
## Improvements
## Bug Fixes