diff --git a/app/js/components/Post.js b/app/js/components/Post.js new file mode 100644 index 0000000..0e3c938 --- /dev/null +++ b/app/js/components/Post.js @@ -0,0 +1,39 @@ +import React, { Component } from 'react'; +import EmbarkJS from 'Embark/EmbarkJS'; +import dateformat from 'dateformat'; + +export class Post extends Component { + + constructor(props) { + super(props); + this.state = { + topic: '', + content: '' + }; + } + + async componentDidMount() { + const ipfsHash = web3.utils.toAscii(this.props.description); + const data = await EmbarkJS.Storage.get(ipfsHash); + const { topic, content } = JSON.parse(data); + + this.setState({ topic, content }); + } + + render() { + const formattedDate = dateformat( + new Date(this.props.creationDate * 1000), + 'yyyy-mm-dd HH:MM:ss' + ); + return ( + +
+

{this.state.topic}

+

{this.state.content}

+

created at {formattedDate} by {this.props.owner}

+ + +
+ ) + } +} diff --git a/app/js/index.js b/app/js/index.js index a2beec8..1235376 100644 --- a/app/js/index.js +++ b/app/js/index.js @@ -7,5 +7,7 @@ import { App } from './components/App'; // e.g if you have a contract named SimpleStorage: //import SimpleStorage from 'Embark/contracts/SimpleStorage'; -render(, document.getElementById('root')); +EmbarkJS.onReady(() => { + render(, document.getElementById('root')); +}); diff --git a/package-lock.json b/package-lock.json index 1b1b2b0..832c0ba 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4,6 +4,11 @@ "lockfileVersion": 1, "requires": true, "dependencies": { + "dateformat": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/dateformat/-/dateformat-3.0.3.tgz", + "integrity": "sha512-jyCETtSl3VMZMWeRo7iY1FL19ges1t55hMo5yaam4Jrsm5EPL89UQkoQRyiI+Yf4k8r2ZpdngkV8hr1lIdjb3Q==" + }, "js-tokens": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz", diff --git a/package.json b/package.json index 1d9c0d7..81c9320 100644 --- a/package.json +++ b/package.json @@ -10,6 +10,7 @@ "homepage": "", "devDependencies": {}, "dependencies": { + "dateformat": "^3.0.3", "react": "^16.4.2", "react-dom": "^16.4.2" }