Skip to content

Commit

Permalink
fix(gatsby-theme-store): complex plp navigation (#749)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabriel Antiqueira authored Jul 1, 2021
1 parent 299baba commit 849f079
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { useLocation } from '@reach/router'
import { parseSearchParamsState } from '@vtex/store-sdk'
import { useMemo } from 'react'
import type { SearchParamsState } from '@vtex/store-sdk'
Expand All @@ -11,8 +10,5 @@ export interface SelectedFacets {
/**
* @description: Hydrates search context for dynamic search pages.
*/
export const useSearchParamsFromUrl = (): SearchParamsState => {
const { href } = useLocation()

return useMemo(() => parseSearchParamsState(new URL(href)), [href])
}
export const useSearchParamsFromUrl = ({ href }: Location): SearchParamsState =>
useMemo(() => parseSearchParamsState(new URL(href)), [href])
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export const search = async (term: string) => {
const path = `/${slugified}`
const exists = await pathExists(path)

params.delete('map')
if (exists) {
// The page /slugified exists, let's navigate to this page
pathname = `/${slugified}`
Expand Down
3 changes: 2 additions & 1 deletion packages/gatsby-theme-store/src/templates/search.browser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ const SearchPage: FC<PageProps> = (props) => {
const {
pageContext: { hideUnavailableItems },
pageContext,
location,
} = props

const searchParams = useSearchParamsFromUrl()
const searchParams = useSearchParamsFromUrl(location)
const variables = useQueryVariablesFromSearchParams(searchParams)
const redirecting = usePersonalizedSearchRedirect(searchParams)

Expand Down

0 comments on commit 849f079

Please sign in to comment.