Skip to content

Commit

Permalink
fix: handle popstate for navigation in mobile entry content (#2038)
Browse files Browse the repository at this point in the history
* fix: handle back navigation to pending feeds on mobile while changing orientation

* fix: navigate to incorrect place

* chore: update `next.md`
  • Loading branch information
CanglongCl authored Dec 8, 2024
1 parent 2b2d56c commit ab85406
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
22 changes: 21 additions & 1 deletion apps/renderer/src/modules/entry-content/index.mobile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import type { FeedModel, InboxModel, SupportedLanguages } from "@follow/models/t
import { stopPropagation } from "@follow/utils/dom"
import { cn } from "@follow/utils/utils"
import { ErrorBoundary } from "@sentry/react"
import { useMemo, useState } from "react"
import { useEffect, useMemo, useState } from "react"

import { useShowAITranslation } from "~/atoms/ai-translation"
import { useAudioPlayerAtomSelector } from "~/atoms/player"
import { useGeneralSettingSelector } from "~/atoms/settings/general"
import { useUISettingKey } from "~/atoms/settings/ui"
import { ShadowDOM } from "~/components/common/ShadowDOM"
import { useNavigateEntry } from "~/hooks/biz/useNavigateEntry"
import { useRouteParamsSelector } from "~/hooks/biz/useRouteParams"
import { useAuthQuery, usePreventOverscrollBounce } from "~/hooks/common"
import { LanguageMap } from "~/lib/translate"
Expand Down Expand Up @@ -40,6 +41,25 @@ export const EntryContent: Component<{
compact?: boolean
classNames?: EntryContentClassNames
}> = ({ entryId, noMedia, compact, classNames }) => {
const navigateEntry = useNavigateEntry()
const { entryId: _, ...params } = useRouteParamsSelector((route) => route)

useEffect(() => {
const handlePopState = (event: PopStateEvent) => {
event.preventDefault()
// This is triggered when the back button is pressed
navigateEntry({ entryId: null, ...params })
}

// Listen to the popstate event (back button)
window.addEventListener("popstate", handlePopState)

// Clean up the event listener on unmount
return () => {
window.removeEventListener("popstate", handlePopState)
}
}, [navigateEntry, params])

const entry = useEntry(entryId)
useTitle(entry?.entries.title)

Expand Down
2 changes: 2 additions & 0 deletions changelog/next.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@
## Improvements

## Bug Fixes

- Resolved issue where back navigation to the pending view would not behave correctly after changing orientation in some device.

0 comments on commit ab85406

Please sign in to comment.