Skip to content

Commit

Permalink
feat: Scroll to top when re-navigating to Discover page while already…
Browse files Browse the repository at this point in the history
… on it (#2371)
  • Loading branch information
zeyios authored Dec 29, 2024
1 parent 1bf2e20 commit a59cf4a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
16 changes: 15 additions & 1 deletion apps/renderer/src/modules/app-layout/subview/index.desktop.tsx
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions changelog/next.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## New Features

- Scroll to top when re-navigating to Discover page while already on it

## Improvements

## Bug Fixes

0 comments on commit a59cf4a

Please sign in to comment.