Skip to content

Commit

Permalink
Merge pull request #95 from cbeard87/enhancement/eslint-config
Browse files Browse the repository at this point in the history
Set up automated formatting
  • Loading branch information
petrsvihlik authored Sep 4, 2018
2 parents bcebbbf + 8b60530 commit 86cc1e5
Show file tree
Hide file tree
Showing 70 changed files with 4,063 additions and 3,057 deletions.
3 changes: 3 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "react-app"
}
32 changes: 17 additions & 15 deletions examples/hoc/src/Components/Article.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
import React, { Component } from 'react';

class Article extends Component {
render() {
return (
<article>
<header>
<h1>{this.props.title}</h1>
</header>
<img alt={this.props.teaserImageAlt} src={this.props.teaserImageSrc} width="500"/>
<p>
{this.props.summary}
</p>
<div dangerouslySetInnerHTML={{__html: this.props.bodyCopy}} />
</article>
);
}
render() {
return (
<article>
<header>
<h1>{this.props.title}</h1>
</header>
<img
alt={this.props.teaserImageAlt}
src={this.props.teaserImageSrc}
width="500"
/>
<p>{this.props.summary}</p>
<div dangerouslySetInnerHTML={{ __html: this.props.bodyCopy }} />
</article>
);
}
}

export default Article;
export default Article;
75 changes: 41 additions & 34 deletions examples/hoc/src/Components/ArticleContainer.js
Original file line number Diff line number Diff line change
@@ -1,44 +1,51 @@
import Article from './Article'
import Article from './Article';

import React, { Component } from 'react';
import config from './deliveryClientConfig';
import withDeliveryClient from './withDeliveryClient';

class ArticleContainer extends Component {
constructor(props) {
super(props)
this.state = {
article: undefined
}
constructor(props) {
super(props);
this.state = {
article: undefined
};
}

componentDidMount() {
this.subscription = this.props.client
.item(this.props.codeName)
.getObservable()
.subscribe(response => {
this.setState({
article: response.item
});
});
}

componentWillUnmount() {
this.subscription.dispose();
}

render() {
if (!this.state.article) {
return <Article />;
}

componentDidMount() {
this.subscription = this.props.client.item(this.props.codeName)
.getObservable()
.subscribe(response => {
this.setState({
article: response.item
});
});
}

componentWillUnmount() {
this.subscription.dispose();
}

render() {
if (!this.state.article) {
return <Article />;
}

const { title, summary, bodyCopy } = this.state.article;
const teaserAlt = this.state.article.teaserImage.assets[0].description;
const teaserUrl = this.state.article.teaserImage.assets[0].url;

return (
<Article title={title.value} summary={summary.value} bodyCopy={bodyCopy.value} teaserImageAlt={teaserAlt} teaserImageSrc={teaserUrl} />
);
}
const { title, summary, bodyCopy } = this.state.article;
const teaserAlt = this.state.article.teaserImage.assets[0].description;
const teaserUrl = this.state.article.teaserImage.assets[0].url;

return (
<Article
title={title.value}
summary={summary.value}
bodyCopy={bodyCopy.value}
teaserImageAlt={teaserAlt}
teaserImageSrc={teaserUrl}
/>
);
}
}

export default withDeliveryClient(config)(ArticleContainer);
export default withDeliveryClient(config)(ArticleContainer);
48 changes: 23 additions & 25 deletions examples/hoc/src/Components/ArticleModel.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,29 @@
import { ContentItem } from 'kentico-cloud-delivery';
import { ContentItem } from 'kentico-cloud-delivery';

export class Article extends ContentItem {
constructor(){
super({
propertyResolver: ((fieldName) => {
constructor() {
super({
propertyResolver: fieldName => {
if (fieldName === 'teaser_image') {
return 'teaserImage';
}

if (fieldName === 'teaser_image'){
return 'teaserImage';
}
if (fieldName === 'post_date') {
return 'postDate';
}

if (fieldName === 'post_date'){
return 'postDate';
}
if (fieldName === 'body_copy') {
return 'bodyCopy';
}

if (fieldName === 'body_copy'){
return 'bodyCopy';
}
if (fieldName === 'related_articles') {
return 'relatedArticles';
}

if (fieldName === 'related_articles'){
return 'relatedArticles';
}

if (fieldName === 'url_pattern'){
return 'urlPattern';
}
}),
})
}

}
if (fieldName === 'url_pattern') {
return 'urlPattern';
}
}
});
}
}
12 changes: 5 additions & 7 deletions examples/hoc/src/Components/deliveryClientConfig.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { TypeResolver } from "kentico-cloud-delivery";
import { TypeResolver } from 'kentico-cloud-delivery';
import { Article } from './ArticleModel';

const config = {
projectId: '975bf280-fd91-488c-994c-2f04416e5ee3',
typeResolvers: [
new TypeResolver('article', () => new Article())
]
}
projectId: '975bf280-fd91-488c-994c-2f04416e5ee3',
typeResolvers: [new TypeResolver('article', () => new Article())]
};

export default config;
export default config;
7 changes: 2 additions & 5 deletions examples/hoc/src/Components/withDeliveryClient.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import React, { Component } from "react";
import { DeliveryClient } from "kentico-cloud-delivery";

import React, { Component } from 'react';
import { DeliveryClient } from 'kentico-cloud-delivery';

export default function withDeliveryClient(config) {

return ChildComponent => {
class WrapperComponent extends Component {

render() {
const client = new DeliveryClient(config);
return <ChildComponent {...this.props} client={client} />;
Expand Down
Loading

0 comments on commit 86cc1e5

Please sign in to comment.