Skip to content

Commit

Permalink
feat(trends): reset page on view change
Browse files Browse the repository at this point in the history
  • Loading branch information
ahonestla committed Jan 16, 2025
1 parent 1e805ac commit df6bd3d
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions client/src/pages/trends/components/panel/header/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useTrendsContext } from "../../../context"
import { trendsViewFromLabel, trendsViewGetConfig } from "../../../config/views"
import useScreenSize from "../../../../../hooks/useScreenSize"
import useTrends from "../../../hooks/useTrends"
import useOptions from "../../../hooks/useOptions"

function TrendsViewMobileButton() {
const intl = useIntl()
Expand Down Expand Up @@ -39,13 +40,15 @@ function TrendsViewButton({ label }) {
trendsYears: { min, max },
} = useTrends()
const { view, setView, setFocus } = useTrendsContext()
const { handlePageChange } = useOptions()
const viewConfig = trendsViewGetConfig(view)
const defaultView = trendsViewFromLabel(label)

const isSelected = Boolean(label === viewConfig.label)
const onButtonClick = () => {
isSelected ? viewConfig?.nextView && setView(viewConfig.nextView) : setView(defaultView)
setFocus("")
isSelected ? viewConfig?.nextView && setView(viewConfig.nextView) : setView(defaultView) // change view
handlePageChange(1) // reset page
setFocus("") // reset focus
}

return (
Expand Down

0 comments on commit df6bd3d

Please sign in to comment.