Skip to content
Permalink
Browse files

Add content to contentlets

  • Loading branch information...
fmontes committed Feb 27, 2019
1 parent 9b817e8 commit e0513fbd561c40b867791c549c76813f065d4193
Showing with 60 additions and 2 deletions.
  1. +7 −0 src/components/ContentGeneric.js
  2. +19 −2 src/components/Contentlet.js
  3. +12 −0 src/components/Event.js
  4. +22 −0 src/components/SimpleWidget.js
@@ -0,0 +1,7 @@
import React from 'react';

const ContentGeneric = (props) => {
return <div dangerouslySetInnerHTML={{__html: props.body}} />;
};

export default ContentGeneric;
@@ -1,7 +1,24 @@
import React from 'react';
import ContentGeneric from './ContentGeneric';
import Event from './Event';
import SimpleWidget from './SimpleWidget';

const Contentlet = (props) => {
return <h3>I'm a Contentlet</h3>;
function getComponent(type) {
switch (type) {
case 'webPageContent':
return ContentGeneric;
case 'SimpleWidget':
return SimpleWidget;
case 'calendarEvent':
return Event;
default:
return ContentGeneric;
}
}

const Contentlet = props => {
const Component = getComponent(props.contentType);
return <Component {...props} />;
};

export default Contentlet;
@@ -0,0 +1,12 @@
import React from 'react';

const Event = props => {
return (
<>
<h3>{props.title}</h3>
<time>{new Date(props.startDate).toDateString()}</time>
</>
);
};

export default Event;
@@ -0,0 +1,22 @@
import React, { Component } from 'react';

export default class SimpleWidget extends Component {
constructor() {
super();
this.state = {
html: ''
};
}
componentDidMount() {
fetch(`http://localhost:8080/api/widget/id/${this.props.identifier}`)
.then(response => response.text())
.then(html => {
this.setState({
html: html
});
});
}
render() {
return <div dangerouslySetInnerHTML={{ __html: this.state.html }} />;
}
}

0 comments on commit e0513fb

Please sign in to comment.
You can’t perform that action at this time.