Created
December 3, 2017 16:46
-
-
Save gullitmiranda/be0b2fcf6b907b973deb1b052e36da2f to your computer and use it in GitHub Desktop.
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
diff --git i/src/components/Pages/Sections/GenericSection.tsx w/src/components/Pages/Sections/GenericSection.tsx | |
index 0e58d20..8a04ac7 100644 | |
--- i/src/components/Pages/Sections/GenericSection.tsx | |
+++ w/src/components/Pages/Sections/GenericSection.tsx | |
@@ -2,17 +2,19 @@ import * as React from 'react'; | |
import { Theme, withStyles, WithStyles, StyleRules } from 'material-ui/styles'; | |
-import Section, { SectionColor, SectionProps } from '../../../ui/Section'; | |
+import { MetaInfo } from '../../PrismicRender'; | |
-import TextBlock, { TextBlockProps } from '../Sections/TextBlock'; | |
+import TextBlock, { TextBlockProps, TextBlockRender } from '../Sections/TextBlock'; | |
import { Text as TextType } from '../Types'; | |
+import Section, { SectionColor, SectionProps } from '../../../ui/Section'; | |
+ | |
import NewsList, { NewsItemType, NewsListProps } from '../../../containers/News/NewsList'; | |
import Newsletter from '../../../components/Newsletter'; | |
export interface GenericSectionProps { | |
primary: { | |
- text: TextType[]; | |
+ text: TextType[] & RichText.RichTextBlock[]; | |
uid?: TextType[]; | |
content_type?: 'digital_assets' | 'news'; | |
content_count?: number; | |
@@ -23,7 +25,7 @@ export interface GenericSectionProps { | |
}; | |
} | |
-type ContentProps = | |
+export type ContentProps = | |
& NewsListProps | |
& SectionProps | |
& TextBlockProps | |
@@ -57,6 +59,23 @@ const renders = { | |
), | |
}; | |
+let headingProps = {} as TextBlockProps; | |
+const paragraphProps = { color: 'inherit' as SectionColor }; | |
+ | |
+class TextRender<T> extends TextBlockRender<T> { | |
+ renderHeading2(meta: MetaInfo<T>) { | |
+ return super.renderHeading2(meta, headingProps); | |
+ } | |
+ | |
+ renderHeading6(meta: MetaInfo<T>) { | |
+ return super.renderHeading6(meta, paragraphProps); | |
+ } | |
+ | |
+ renderParagraph(meta: MetaInfo<T>) { | |
+ return super.renderParagraph(meta, paragraphProps); | |
+ } | |
+} | |
+ | |
class GenericSection extends React.Component<GenericSectionProps & WithStyles<GenericSectionClassKey>> { | |
render() { | |
const { classes, primary, contentItems } = this.props; | |
@@ -72,11 +91,10 @@ class GenericSection extends React.Component<GenericSectionProps & WithStyles<Ge | |
const componentProps = { | |
limit: content_count, | |
[content_type]: contentItems[content_type], | |
- id: uid, | |
primary, | |
color, | |
classes, | |
- }; | |
+ } as ContentProps; | |
const Component = renders[content_type]; | |
if (Component) { | |
@@ -84,14 +102,11 @@ class GenericSection extends React.Component<GenericSectionProps & WithStyles<Ge | |
} | |
} | |
- const heading2Props = { | |
- color: (color === 'primary' ? 'inherit' : 'primary') as SectionColor, | |
- }; | |
- const paragraphProps = { color: 'inherit' as SectionColor }; | |
+ headingProps.color = (color === 'primary' ? 'inherit' : 'primary') as SectionColor; | |
return ( | |
<Section color={color} id={uid} className={classes.root}> | |
- <TextBlock primary={primary} heading2Props={heading2Props} paragraphProps={paragraphProps} /> | |
+ <TextBlock primary={primary} richRender={TextRender} /> | |
{content} | |
</Section> | |
diff --git i/src/components/Pages/Sections/TextBlock.tsx w/src/components/Pages/Sections/TextBlock.tsx | |
index 3b946d3..5eaa1cd 100644 | |
--- i/src/components/Pages/Sections/TextBlock.tsx | |
+++ w/src/components/Pages/Sections/TextBlock.tsx | |
@@ -36,30 +36,37 @@ export const styles = (theme: Theme): StyleRules => ({ | |
type ClassKey = 'root' | 'lists' | 'listItem' | 'listIcon'; | |
-export type TextBlockProps = SectionHeaderProps & TypographyProps & { | |
- primary: { | |
- uid?: Text[]; | |
- text: RichText.RichTextBlock[]; | |
+export class TextBlockRender<T> extends PrismicRender<T, WithStyles<ClassKey>> { | |
+ renderHeading2({ key, children }: MetaInfo<T>, props?: TypographyProps) { | |
+ return <SectionHeader component="h2" key={key} children={children} {...props} />; | |
} | |
-}; | |
-class Render<T> extends PrismicRender<T, WithStyles<ClassKey>> { | |
- renderHeading2({ key, children }: MetaInfo<T>) { | |
- return <SectionHeader component="h2" key={key} children={children} />; | |
+ renderHeading4({ key, children }: MetaInfo<T>, props?: TypographyProps) { | |
+ return ( | |
+ <Typography | |
+ key={key} | |
+ type="title" | |
+ color="primary" | |
+ component="h4" | |
+ children={children} | |
+ gutterBottom | |
+ {...props} | |
+ /> | |
+ ); | |
} | |
- renderHeading6({ key, children }: MetaInfo<T>) { | |
+ renderHeading6({ key, children }: MetaInfo<T>, props?: TypographyProps) { | |
return ( | |
<Grid key={key} container justify="center" spacing={0}> | |
<Grid item xs={12} md={6}> | |
- <Typography align="center" paragraph children={children} /> | |
+ <Typography align="center" paragraph children={children} {...props} /> | |
</Grid> | |
</Grid> | |
); | |
} | |
- renderParagraph({ key, children }: MetaInfo<T>) { | |
- return <Typography key={key} align="center" paragraph children={children} />; | |
+ renderParagraph({ key, children }: MetaInfo<T>, props?: TypographyProps) { | |
+ return <Typography key={key} align="center" paragraph children={children} {...props} />; | |
} | |
renderList({ key, children }: MetaInfo<T>) { | |
@@ -81,14 +88,22 @@ class Render<T> extends PrismicRender<T, WithStyles<ClassKey>> { | |
} | |
} | |
+export type TextBlockProps = SectionHeaderProps & TypographyProps & { | |
+ primary: { | |
+ uid?: Text[]; | |
+ text: RichText.RichTextBlock[]; | |
+ }; | |
+ richRender?: typeof TextBlockRender; | |
+}; | |
+ | |
class TextBlock extends React.Component<TextBlockProps & WithStyles<ClassKey>> { | |
render() { | |
- const { classes, primary } = this.props; | |
+ const { classes, primary, richRender: RichRender = TextBlockRender } = this.props; | |
const { text, uid: [{ text: uid }] = [{ text: undefined }]} = primary; | |
return ( | |
<GridContainer id={uid} className={classes.root}> | |
- <Render richText={text} classes={classes} /> | |
+ <RichRender richText={text} classes={classes} /> | |
</GridContainer> | |
); | |
} | |
diff --git i/src/containers/Home/OurServices.tsx w/src/containers/Home/OurServices.tsx | |
index 89def7c..d714561 100644 | |
--- i/src/containers/Home/OurServices.tsx | |
+++ w/src/containers/Home/OurServices.tsx | |
@@ -9,9 +9,10 @@ import Button, { ButtonProps } from '../../ui/Button'; | |
import { TextType, LinkType } from '../../components/Pages'; | |
import TextBlock, { TextBlockProps } from '../../components/Pages/Sections/TextBlock'; | |
import { RichUrlToLinkProps } from '../../components/Pages/utils'; | |
+import { RichText } from '../../components/PrismicRender'; | |
export type OurServicesItemsType = { | |
- text: TextType[]; | |
+ text: TextType[] & RichText.RichTextBlock[]; | |
learn_more_link: LinkType; | |
start_it_now_link: LinkType; | |
}; | |
diff --git i/src/static/__tests__/prismic.spec.js w/src/static/__tests__/prismic.spec.js | |
index 75cf368..af38458 100644 | |
--- i/src/static/__tests__/prismic.spec.js | |
+++ w/src/static/__tests__/prismic.spec.js | |
@@ -34,6 +34,40 @@ describe('Prismic client', () => { | |
expect(news).toHaveProperty('pt-BR', expected); | |
}); | |
+ it('should return a digital_assets', async () => { | |
+ const expected = expect.arrayContaining([ | |
+ expect.objectContaining({ | |
+ text: expect.arrayContaining([ | |
+ expect.objectContaining({ | |
+ type: "heading4", | |
+ text: expect.any(String), | |
+ }), | |
+ expect.objectContaining({ | |
+ type: "paragraph", | |
+ text: expect.any(String), | |
+ }), | |
+ ]), | |
+ logo: expect.objectContaining({ | |
+ url: expect.any(String), | |
+ }), | |
+ cover: expect.objectContaining({ | |
+ url: expect.any(String), | |
+ }), | |
+ more_link: expect.objectContaining({ | |
+ link_type: "Web", | |
+ url: expect.any(String) | |
+ }), | |
+ }) | |
+ ]); | |
+ | |
+ const digitalAssets = await prismic.digital_assets(); | |
+ // const { en: [da] } = digitalAssets; | |
+ // jclrz(da); | |
+ | |
+ expect(digitalAssets).toHaveProperty('en', expected); | |
+ // expect(digitalAssets).toHaveProperty('pt-BR', expected); | |
+ }); | |
+ | |
it('should return a page', async() => { | |
const expected = expect.arrayContaining([ | |
expect.objectContaining({ | |
diff --git i/src/static/prismic.js w/src/static/prismic.js | |
index 22ab478..e3565af 100644 | |
--- i/src/static/prismic.js | |
+++ w/src/static/prismic.js | |
@@ -43,6 +43,11 @@ export class Contents { | |
return this.parseDocuments(documents); | |
} | |
+ async digital_assets(lang = '*') { | |
+ const { digital_assets: documents } = await this.get('digital_assets', { lang }); | |
+ return this.parseDocuments(documents); | |
+ } | |
+ | |
parseDocuments(documents) { | |
return _.groupBy( | |
_.reduce(documents, (results, { lang, data }) => { | |
diff --git i/src/static/routes.js w/src/static/routes.js | |
index 7c53366..12ef452 100644 | |
--- i/src/static/routes.js | |
+++ w/src/static/routes.js | |
@@ -61,6 +61,7 @@ async function localizedRoutes(routers) { | |
about: await prismic.page('about'), | |
// Content itens | |
+ digital_assets: await prismic.digital_assets(), | |
news: await prismic.news(), | |
}; | |
@@ -69,7 +70,7 @@ async function localizedRoutes(routers) { | |
{ | |
path: `/${lang}`, | |
component: 'src/containers/Home', | |
- getProps: makeGetProps(lang, data, ['home', 'news']), | |
+ getProps: makeGetProps(lang, data, ['home', 'news', 'digital_assets'], true), | |
}, | |
{ | |
path: `/${lang}/ico`, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment