fix: search api on blog
This commit is contained in:
parent
04d995933e
commit
c17090fa47
@ -2,7 +2,7 @@ overwrite: true
|
||||
schema:
|
||||
- 'https://graphql.datocms.com/':
|
||||
headers:
|
||||
Authorization: Bearer ${CMS_ACCESS_TOKEN}
|
||||
Authorization: Bearer ${NEXT_PUBLIC_CMS_ACCESS_TOKEN}
|
||||
documents: './src/**/*.{gql,graphql}'
|
||||
generates:
|
||||
./src/lib/cms/generated.ts:
|
||||
|
||||
@ -9,7 +9,7 @@ const cms = (preview?: boolean) => {
|
||||
return getSdk(
|
||||
new GraphQLClient(preview ? previewEndpoint : endpoint, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${process.env.CMS_ACCESS_TOKEN}`
|
||||
Authorization: `Bearer ${process.env.NEXT_PUBLIC_CMS_ACCESS_TOKEN}`
|
||||
}
|
||||
})
|
||||
)
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
import { PageLayout } from 'components/layout/page'
|
||||
import {
|
||||
getBlogPosts,
|
||||
getBlogPosts as serverGetBlogPosts,
|
||||
getBlogPostsCategories as serverGetBlogPostsCategories
|
||||
} from 'lib/blog'
|
||||
@ -17,7 +18,7 @@ import SearchBar, {
|
||||
SearchContainer
|
||||
} from '~/components/sections/blog/search'
|
||||
import { CategoryFragment } from '~/lib/cms/generated'
|
||||
import { getHrefWithQuery, getQueryParams, makeQuery } from '~/lib/utils/router'
|
||||
import { getHrefWithQuery, makeQuery } from '~/lib/utils/router'
|
||||
|
||||
const getMatchingCategory = (categories: CategoryFragment[], c?: string) =>
|
||||
categories.find((cat) => cat.slug === c)
|
||||
@ -54,7 +55,7 @@ const BlogIndexPage = ({
|
||||
|
||||
return clientGetBlogPosts({
|
||||
page: pageParam,
|
||||
category: matchingCat?.id ?? null,
|
||||
category: matchingCat?.id ?? undefined,
|
||||
search: queryKey[3] as string
|
||||
})
|
||||
},
|
||||
@ -139,36 +140,31 @@ const clientGetBlogPosts = async ({
|
||||
step,
|
||||
filterIds,
|
||||
category,
|
||||
search,
|
||||
locale
|
||||
search
|
||||
}: {
|
||||
page?: number
|
||||
step?: number
|
||||
filterIds?: string[]
|
||||
category?: string
|
||||
search?: string
|
||||
locale?: string
|
||||
}): Promise<{
|
||||
pagination: {
|
||||
page: number
|
||||
nextPage: number
|
||||
nextPage: number | null
|
||||
totalPages: number
|
||||
step: number
|
||||
total: number
|
||||
}
|
||||
data: any[]
|
||||
}> => {
|
||||
const searchParams = getQueryParams({
|
||||
page: page?.toString() || null,
|
||||
step: step?.toString() || null,
|
||||
filterIds: filterIds?.join(',') || null,
|
||||
category: category || null,
|
||||
search: search || null,
|
||||
locale: locale || null
|
||||
console.log(category, search)
|
||||
const allBlogPosts = await getBlogPosts({
|
||||
page,
|
||||
step,
|
||||
filterIds: filterIds,
|
||||
category,
|
||||
search
|
||||
})
|
||||
const allBlogPosts = await (
|
||||
await fetch(`/api/blog-posts?${searchParams.toString()}`)
|
||||
).json()
|
||||
|
||||
return allBlogPosts
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user