-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add get Pages query * Add landing page * Resolve fetched content * Render Dynamic Page * Setup Components Mapping
- Loading branch information
Showing
20 changed files
with
996 additions
and
100 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 |
---|---|---|
@@ -1,55 +1,16 @@ | ||
import { Fragment } from 'react'; | ||
import { Page, Hero, Display, Heading, CategoryCard, ProductSlider } from '~/components'; | ||
import type { RenderContentProps } from '~/components'; | ||
import { BlockComponent } from '~/hooks'; | ||
import { getBlockComponent } from '../blocksConfig'; | ||
import { UnknownBlock } from './UnknownBlock'; | ||
|
||
export function RenderContent({ content, ...attributes }: RenderContentProps): JSX.Element { | ||
type RenderContentProps = { | ||
contentBlock: BlockComponent; | ||
}; | ||
|
||
export function RenderContent({ contentBlock, ...attributes }: RenderContentProps) { | ||
const BlockComponent = getBlockComponent(contentBlock) || UnknownBlock; | ||
return ( | ||
<div {...attributes}> | ||
{content.map(({ fields }, index) => ( | ||
<Fragment key={`${fields.component}-${index}`}> | ||
{(() => { | ||
switch (fields.component) { | ||
case 'Hero': { | ||
return ( | ||
<Hero | ||
image={fields.image} | ||
subtitle={fields.subtitle} | ||
title={fields.title} | ||
description={fields.description} | ||
primaryButtonLink={fields.primaryButtonLink} | ||
primaryButtonText={fields.primaryButtonText} | ||
secondaryButtonLink={fields.secondaryButtonLink} | ||
secondaryButtonText={fields.secondaryButtonText} | ||
/> | ||
); | ||
} | ||
case 'Heading': { | ||
return <Heading title={fields.title} tag={fields.tag} className={fields.className} />; | ||
} | ||
case 'Card': { | ||
return <CategoryCard items={fields.items} />; | ||
} | ||
case 'Display': { | ||
return <Display items={fields.items} />; | ||
} | ||
case 'ProductSlider': { | ||
return ( | ||
<ProductSlider | ||
collection="hidden-homepage" | ||
className="max-w-screen-3xl mx-auto px-4 md:px-10 mb-20" | ||
/> | ||
); | ||
} | ||
case 'Page': { | ||
return <Page />; | ||
} | ||
default: { | ||
return <p>component {fields.component} is not registered</p>; | ||
} | ||
} | ||
})()} | ||
</Fragment> | ||
))} | ||
<div> | ||
<BlockComponent {...contentBlock.fields} contentBlock={contentBlock} {...attributes} /> | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { BlockComponent } from '~/hooks'; | ||
|
||
type UnknownBlockProps = { | ||
contentBlock: BlockComponent; | ||
}; | ||
|
||
export const UnknownBlock = ({ contentBlock }: UnknownBlockProps) => { | ||
return ( | ||
<div> | ||
<h3>Unknown Content Block</h3> | ||
<p>Type: {contentBlock.contentType}</p> | ||
<p>ID: {contentBlock.id}</p> | ||
{/* <pre>{JSON.stringify(contentBlock.fields, null, 2)}</pre> */} | ||
<hr /> | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,21 @@ | ||
import type { ContentDynamicPage } from '~/hooks'; | ||
/* eslint-disable no-use-before-define */ | ||
type Component = { | ||
__typename: string; | ||
id: string; | ||
type: string; | ||
fields: ContentField[]; | ||
}; | ||
|
||
type ContentField = { | ||
type: string; | ||
key: string; | ||
value: string; | ||
reference?: Component | null; | ||
}; | ||
|
||
export type RenderContentProps = { | ||
content: ContentDynamicPage['content']; | ||
type ContentBlock = { | ||
__typename: string; | ||
id: string; | ||
type: string; | ||
fields: ContentField[]; | ||
}; |
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,21 @@ | ||
import React from 'react'; | ||
import { BlockComponent } from '~/hooks'; | ||
import withShopify from '~/sdk/shopify/withShopify'; | ||
|
||
type Props = { | ||
contentBlock: BlockComponent; | ||
}; | ||
|
||
export const RichText = ({ contentBlock }: Props) => { | ||
return ( | ||
<div> | ||
<h3>Rich Text Block</h3> | ||
<p>Type: {contentBlock.contentType}</p> | ||
<p>ID: {contentBlock.id}</p> | ||
{/* <pre>{JSON.stringify(contentBlock.fields, null, 2)}</pre> */} | ||
<hr /> | ||
</div> | ||
); | ||
}; | ||
|
||
export const RichTextBlock = withShopify({ wrapperFn: (v) => v, isDebug: true })(RichText); |
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 @@ | ||
export * from './RichText'; |
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,21 @@ | ||
import { DisplayBlock, CategoryCardBlock, HeroBlock, ProductSliderBlock } from '~/components'; | ||
import { BlockComponent } from '~/hooks'; | ||
import { RichTextBlock } from './RichText'; | ||
|
||
const contentMap = { | ||
// display: () => DisplayBlock, | ||
collection_card: () => CategoryCardBlock, | ||
// hero: () => HeroBlock, | ||
// richtext_block: () => RichTextBlock, | ||
// product_slider: () => ProductSliderBlock, | ||
}; | ||
|
||
type ContentMapKey = keyof typeof contentMap; | ||
|
||
export const getBlockComponent = (contentBlock: BlockComponent) => { | ||
const getComponent = contentMap[contentBlock.contentType as ContentMapKey]; | ||
if (!getComponent) { | ||
return; | ||
} | ||
return getComponent(); | ||
}; |
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,77 @@ | ||
export const getPageQuery = `#graphql | ||
query GetPage($slug: String!) { | ||
page(handle: $slug) { | ||
id | ||
title | ||
handle | ||
seo { | ||
title | ||
description | ||
} | ||
content: metafield(namespace: "custom", key: "content") { | ||
id | ||
key | ||
namespace | ||
value | ||
references(first: 50) { | ||
edges { | ||
node { | ||
__typename | ||
... on Metaobject { | ||
id | ||
type | ||
fields { | ||
type | ||
key | ||
value | ||
reference { | ||
__typename | ||
... on Collection { | ||
id | ||
title | ||
slug: handle | ||
} | ||
... on Product { | ||
id | ||
title | ||
slug: handle | ||
} | ||
... on Metaobject { | ||
id | ||
handle | ||
type | ||
fields { | ||
key | ||
type | ||
value | ||
reference { | ||
__typename | ||
... on Page { | ||
id | ||
title | ||
slug: handle | ||
} | ||
... on MediaImage { | ||
id | ||
alt | ||
image { | ||
url | ||
altText | ||
width | ||
height | ||
id | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
`; |
Oops, something went wrong.