Skip to content
This repository has been archived by the owner on Jun 2, 2022. It is now read-only.

Commit

Permalink
chore: Simpify search page (#125)
Browse files Browse the repository at this point in the history
  • Loading branch information
tlgimenes authored Dec 2, 2021
1 parent 4e1ba86 commit 0ebc0a7
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 96 deletions.
39 changes: 35 additions & 4 deletions src/pages/s.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { parseSearchState, SearchProvider } from '@faststore/sdk'
import { parseSearchState, SearchProvider, useSession } from '@faststore/sdk'
import { graphql } from 'gatsby'
import React, { useMemo } from 'react'
import ProductGallery from 'src/components/sections/ProductGallery'
import { ITEMS_PER_PAGE } from 'src/constants'
import { applySearchState } from 'src/sdk/search/state'
import View from 'src/views/search'
import type { PageProps } from 'gatsby'
import type {
SearchPageQueryQuery,
SearchPageQueryQueryVariables,
} from '@generated/graphql'
import { GatsbySeo } from 'gatsby-plugin-next-seo'

export type Props = PageProps<
SearchPageQueryQuery,
Expand All @@ -19,7 +20,13 @@ const useSearchParams = ({ href }: Location) =>
useMemo(() => href && parseSearchState(new URL(href)), [href])

function Page(props: Props) {
const {
data: { site },
} = props

const { locale } = useSession()
const searchParams = useSearchParams(props.location)
const title = site?.siteMetadata?.title ?? ''

if (!searchParams) {
return null
Expand All @@ -31,15 +38,39 @@ function Page(props: Props) {
itemsPerPage={ITEMS_PER_PAGE}
{...searchParams}
>
<View {...props} />
{/* SEO */}
<GatsbySeo
noindex
language={locale}
title={title}
description={site?.siteMetadata?.description ?? ''}
titleTemplate={site?.siteMetadata?.titleTemplate ?? ''}
openGraph={{
type: 'website',
title,
description: site?.siteMetadata?.description ?? '',
}}
/>

{/*
Sections: Components imported from '../components/sections' only.
Do not import or render components from any other folder in here.
*/}
<h1 className="absolute top-[-100px]">{title}</h1>

<ProductGallery title="Search Results" />
</SearchProvider>
)
}

export const query = graphql`
query SearchPageQuery {
site {
...SearchSeoFragment_site
siteMetadata {
titleTemplate
title
description
}
}
}
`
Expand Down
63 changes: 0 additions & 63 deletions src/views/search/Seo/index.tsx

This file was deleted.

29 changes: 0 additions & 29 deletions src/views/search/index.tsx

This file was deleted.

0 comments on commit 0ebc0a7

Please sign in to comment.