diff --git a/app/queries/sanity.js b/app/queries/sanity.js index a412ae6..b272f70 100644 --- a/app/queries/sanity.js +++ b/app/queries/sanity.js @@ -77,18 +77,33 @@ const MODULE_STANDARD_TEXT = groq` } ` +const MODULE_HERO = groq` + (_type == 'module.hero') => { + 'bgColor': bgColor.hex, + 'image': image.asset-> { + metadata, + url + }, + text[] { + ${richText} + } + } +` + const MODULES = groq` _type, _key, ${MODULE_STANDARD_TEXT}, + ${MODULE_HERO} ` const PAGE_MODULES = groq` _type, _key, ${MODULE_STANDARD_TEXT}, + ${MODULE_HERO} ` const pageQuery = groq` @@ -100,6 +115,12 @@ const pageQuery = groq` } ` +const homeQuery = groq` + 'modules': modules[] { + ${PAGE_MODULES} + } +` + const productQuery = groq` _type, 'slug': store.slug.current, @@ -133,4 +154,12 @@ export const QUERY_PAGE = (slug) => groq`*[ !(_id in path("drafts.**")) ][0] { ${pageQuery} -}` \ No newline at end of file +}` + +export const QUERY_HOME = groq` + *[_type == 'home' && + !(_id in path("drafts.**"))] { + ${homeQuery} + }[0] +` + diff --git a/app/routes/($locale)._index.jsx b/app/routes/($locale)._index.jsx index 5248393..3a86d91 100644 --- a/app/routes/($locale)._index.jsx +++ b/app/routes/($locale)._index.jsx @@ -4,6 +4,8 @@ import {Await, useLoaderData, useFetcher, Link} from '@remix-run/react'; import { AnalyticsPageType } from '@shopify/hydrogen'; import { flattenConnection } from '@shopify/hydrogen-react' +import { QUERY_HOME } from '~/queries/sanity' + import PageComponentList from '~/components/PageComponentList' export async function loader({context}) { @@ -12,22 +14,9 @@ export async function loader({context}) { const products = await context.storefront.query(PRODUCT_QUERY) const articles = await context.storefront.query(ARTICLES_QUERY) - const sanityPage = await context.sanity.fetch(` - *[_type == 'home'] { - ..., - modules[] { - _type, - _key, - (_type == 'module.hero') => { - 'bgColor': bgColor.hex, - 'image': image.asset-> { - metadata, - url - }, - text - } - } - }[0]`) + const sanityPage = await context.sanity.fetch(QUERY_HOME) + + console.log('sanityPage', sanityPage) // We're not covering accounts/auth in this class // const customerAccessToken = await context.session.get('customerAccessToken'); @@ -66,9 +55,6 @@ export default function Homepage() { return (