Skip to content

Commit

Permalink
fix: scroll to top when switch to other entry
Browse files Browse the repository at this point in the history
Signed-off-by: Innei <i@innei.in>
  • Loading branch information
Innei committed Aug 8, 2024
1 parent 8e75a8c commit 4ec1c93
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/renderer/src/modules/entry-content/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import { Queries } from "@renderer/queries"
import { useEntry, useEntryReadHistory } from "@renderer/store/entry"
import { useFeedById, useFeedHeaderTitle } from "@renderer/store/feed"
import type { FC, ReactNode } from "react"
import { useEffect, useLayoutEffect, useState } from "react"
import { useEffect, useLayoutEffect, useRef, useState } from "react"

import { LoadingCircle } from "../../components/ui/loading"
import { EntryPlaceholderDaily } from "../ai/ai-daily/EntryPlaceholderDaily"
Expand Down Expand Up @@ -136,6 +136,11 @@ function EntryContentRender({ entryId }: { entryId: string }) {
const view = useRouteParamsSelector((route) => route.view)

const isInReadabilityMode = useEntryIsInReadability(entryId)
const scrollerRef = useRef<HTMLDivElement>(null)

useEffect(() => {
scrollerRef.current?.scrollTo(0, 0)
}, [entryId])
if (!entry) return null

return (
Expand All @@ -155,6 +160,7 @@ function EntryContentRender({ entryId }: { entryId: string }) {
mask={false}
rootClassName="h-0 grow min-w-0 overflow-y-auto @container"
viewportClassName="p-5"
ref={scrollerRef}
>
<m.div
style={
Expand Down Expand Up @@ -278,6 +284,9 @@ const TitleMetaHandler: Component<{
const { title: feedTitle } = useFeedById(feedId)!

const atTop = useIsSoFWrappedElement()
useEffect(() => {
setEntryContentScrollToTop(false)
}, [entryId])
useLayoutEffect(() => {
setEntryContentScrollToTop(atTop)
}, [atTop])
Expand Down

0 comments on commit 4ec1c93

Please sign in to comment.