Skip to content

Commit

Permalink
reusable modules rendered on the page
Browse files Browse the repository at this point in the history
  • Loading branch information
iamkevingreen committed Sep 24, 2023
1 parent 6c55fa3 commit e09c58b
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 4 deletions.
19 changes: 18 additions & 1 deletion app/components/PageComponentList.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react';
import reduce from 'lodash/reduce'

import { Hero } from '~/components/sharable/hero'
import { ValueProps } from '~/components/sharable/valueProps'
Expand All @@ -12,8 +13,24 @@ const COMPONENTS = {
'module.productGrid': ProductGrid
};

const unfurlGlobalComponents = (components = []) => {
return reduce(
components,
(componentsWithGlobalsUnfurled, component) => {
if (component._type === 'module.reusableModule') {
const globalComponents = component.module.modules || []
return [...componentsWithGlobalsUnfurled, ...globalComponents]
} else {
return [...componentsWithGlobalsUnfurled, component]
}
},
[],
)
}

const PageComponentList = ({components = [], componentProps = {}}) => {
const componentRows = components?.map((component, index) => {
const allComponents = unfurlGlobalComponents(components)
const componentRows = allComponents?.map((component, index) => {
const Component = COMPONENTS[component._type];

if (!Component)
Expand Down
18 changes: 18 additions & 0 deletions app/queries/sanity.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,23 @@ const MODULE_FAQS = groq`
}
`

const MODULE_REUSABLE = groq`
(_type == 'module.reusableModule') => {
'module': module-> {
'modules': reusableComponentList[] {
_type,
_key,
${MODULE_STANDARD_TEXT},
${MODULE_VALUE_PROPS},
${MODULE_FAQS},
${MODULE_HERO},
${MODULE_IMAGE},
${MODULE_BIG_BENEFITS}
}
}
}
`

const MODULES = groq`
_type,
_key,
Expand All @@ -250,6 +267,7 @@ const PAGE_MODULES = groq`
_key,
${MODULE_STANDARD_TEXT},
${MODULE_HERO},
${MODULE_REUSABLE},
${MODULE_PRODUCT_GRID},
${MODULE_VALUE_PROPS},
${MODULE_FAQS}
Expand Down
2 changes: 0 additions & 2 deletions app/root.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,6 @@ export default function App() {

const {promo} = data.layout;

console.log('layout', data.layout)

return (
<ShopifyProvider {...shopifyConfig}>
<html lang="en">
Expand Down
4 changes: 4 additions & 0 deletions app/routes/($locale)._index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ export async function loader({context}) {
}
})

sanityData.homepage.modules.forEach(module => {
console.log('module', module)
})

const shopifyProducts = await context.storefront.query(SHOPIFY_PRODUCTS_QUERY, {
variables: {
ids: [...new Set(productIds)],
Expand Down
2 changes: 1 addition & 1 deletion cms/schemas/modules/reusableModule.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default {
],
preview: {
select: {
title: 'title',
title: 'title'
},
prepare: selection => ({
...selection,
Expand Down

0 comments on commit e09c58b

Please sign in to comment.