Extracting data from IPFS
This commit is contained in:
parent
9d82dbae7f
commit
226ae6d768
|
@ -34,11 +34,7 @@ class ProposalContainer extends React.Component {
|
||||||
// TODO: populate proposals
|
// TODO: populate proposals
|
||||||
let proposalList = [
|
let proposalList = [
|
||||||
{
|
{
|
||||||
description: "0x68747470733a2f2f69646561732e7374617475732e696d2f69646561732f3038382d646170702d657870657269656e6365",
|
description: "QmZ4hQ5jKUqtHEXhXDVSz81JexMoDmVfiypECFQZZibyrS",
|
||||||
approved: true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
description: "0x68747470733a2f2f69646561732e7374617475732e696d2f69646561732f3039302d6272616e63682d706572662d7374617473",
|
|
||||||
approved: true
|
approved: true
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
|
@ -1,39 +1,47 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import $ from 'jquery';
|
import $ from 'jquery';
|
||||||
import {Button} from 'react-bootstrap';
|
import {Button} from 'react-bootstrap';
|
||||||
|
import EmbarkJS from 'Embark/EmbarkJS';
|
||||||
|
import ProposalForm from './proposal-form';
|
||||||
|
|
||||||
class Proposal extends React.Component {
|
class Proposal extends React.Component {
|
||||||
|
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
|
|
||||||
this.state = {
|
this.state = {
|
||||||
url: web3.utils.toAscii(props.data.description),
|
url: null,
|
||||||
content: ''
|
title: null,
|
||||||
|
description: null
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount(){
|
componentDidMount(){
|
||||||
fetch(this.state.url)
|
__embarkContext.execWhenReady(() => {
|
||||||
.then((res) => {
|
EmbarkJS.Storage.get(this.props.data.description)
|
||||||
return res.text();
|
.then((content) => {
|
||||||
})
|
let jsonObj = JSON.parse(content);
|
||||||
.then((data) => {
|
this.setState({
|
||||||
data = data.replace(/<svg.+\/svg>/, '');
|
url: jsonObj.url,
|
||||||
this.setState({'content': data});
|
title: jsonObj.title,
|
||||||
});
|
description: jsonObj.description
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
if(err){
|
||||||
|
// TODO handle error
|
||||||
|
console.log("Storage get Error => " + err.message);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
render(){
|
render(){
|
||||||
let $content = $(this.state.content);
|
|
||||||
const title = $('h1.post-title', $content).text();
|
|
||||||
const summary = $('h2#summary', $content).next().text();
|
|
||||||
|
|
||||||
return (<div>
|
return (<div>
|
||||||
<h3>{ title }</h3>
|
<h3>{ this.state.title }</h3>
|
||||||
|
<p>{ this.state.description }</p>
|
||||||
<a href={ this.state.url } target="_blank">{ this.state.url }</a>
|
<a href={ this.state.url } target="_blank">{ this.state.url }</a>
|
||||||
<p>{summary}</p>
|
<ProposalForm />
|
||||||
<Button bsStyle="primary">Vote</Button>
|
|
||||||
<Button bsStyle="link">Cancel</Button>
|
|
||||||
</div>);
|
</div>);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue