Extracting data from IPFS

This commit is contained in:
Richard Ramos 2018-05-29 11:00:21 -04:00
parent 9d82dbae7f
commit 226ae6d768
2 changed files with 27 additions and 23 deletions

View File

@ -34,11 +34,7 @@ class ProposalContainer extends React.Component {
// TODO: populate proposals
let proposalList = [
{
description: "0x68747470733a2f2f69646561732e7374617475732e696d2f69646561732f3038382d646170702d657870657269656e6365",
approved: true
},
{
description: "0x68747470733a2f2f69646561732e7374617475732e696d2f69646561732f3039302d6272616e63682d706572662d7374617473",
description: "QmZ4hQ5jKUqtHEXhXDVSz81JexMoDmVfiypECFQZZibyrS",
approved: true
}
]

View File

@ -1,39 +1,47 @@
import React from 'react';
import $ from 'jquery';
import {Button} from 'react-bootstrap';
import EmbarkJS from 'Embark/EmbarkJS';
import ProposalForm from './proposal-form';
class Proposal extends React.Component {
constructor(props) {
super(props);
this.state = {
url: web3.utils.toAscii(props.data.description),
content: ''
url: null,
title: null,
description: null
};
}
componentDidMount(){
fetch(this.state.url)
.then((res) => {
return res.text();
})
.then((data) => {
data = data.replace(/<svg.+\/svg>/, '');
this.setState({'content': data});
});
__embarkContext.execWhenReady(() => {
EmbarkJS.Storage.get(this.props.data.description)
.then((content) => {
let jsonObj = JSON.parse(content);
this.setState({
url: jsonObj.url,
title: jsonObj.title,
description: jsonObj.description
})
})
.catch((err) => {
if(err){
// TODO handle error
console.log("Storage get Error => " + err.message);
}
});
});
}
render(){
let $content = $(this.state.content);
const title = $('h1.post-title', $content).text();
const summary = $('h2#summary', $content).next().text();
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>
<p>{summary}</p>
<Button bsStyle="primary">Vote</Button>
<Button bsStyle="link">Cancel</Button>
<ProposalForm />
</div>);
}