-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add sanity client query support
Add sanity client to query data in client ISSUES CLOSED: #4595
- Loading branch information
1 parent
30bd26e
commit a2a44f9
Showing
16 changed files
with
1,579 additions
and
261 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"path": "./src/**/*.{ts,tsx,js,jsx}", | ||
"schema": "./src/sanity/extract.json", | ||
"generates": "./src/sanity/types.ts" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,18 @@ | ||
import { getPayload, Where } from "payload"; | ||
import { PropDocumentation } from "@/components/prop-documentation/PropDocumentation"; | ||
import { RichText } from "@/components/rich-text"; | ||
import configPromise from "@/payload.config"; | ||
import { client } from "@/sanity/client"; | ||
import { componentPageBySlugQuery } from "@/sanity/queries/componentPage"; | ||
|
||
export default async function Page({ | ||
params, | ||
}: { | ||
params: Promise<{ slug: string }>; | ||
}) { | ||
const payload = await getPayload({ | ||
config: configPromise, | ||
}); | ||
|
||
const slug = (await params).slug; | ||
|
||
const query: Where = { | ||
slug: { | ||
equals: slug, | ||
}, | ||
}; | ||
|
||
const data = await payload.find({ | ||
collection: "component-page", | ||
where: query, | ||
}); | ||
const data = await client.fetch(componentPageBySlugQuery, { slug }); | ||
|
||
return ( | ||
<> | ||
<div>Hei jeg er {data.docs?.[0]?.title || "ikke i databasen"}</div> | ||
|
||
{data.docs[0]?.content && ( | ||
<RichText data={data.docs[0].content}></RichText> | ||
)} | ||
|
||
{data.docs?.[0]?.["component-folder"] && ( | ||
<PropDocumentation | ||
component={data.docs[0]?.["component-folder"]} | ||
/> | ||
)} | ||
<div>Hei jeg er {data?.title || "ikke i databasen"}</div> | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { createClient } from "next-sanity"; | ||
|
||
export const client = createClient({ | ||
projectId: process.env.NEXT_PUBLIC_SANITY_STUDIO_PROJECT_ID || "", | ||
dataset: process.env.NEXT_PUBLIC_SANITY_STUDIO_DATASET || "test", | ||
}); |
Oops, something went wrong.