From 226ae6d768b20751d2113b03ce4958d61d8abc94 Mon Sep 17 00:00:00 2001 From: Richard Ramos Date: Tue, 29 May 2018 11:00:21 -0400 Subject: [PATCH] Extracting data from IPFS --- .../voting-dapp/proposal-container.js | 6 +-- app/components/voting-dapp/proposal.js | 44 +++++++++++-------- 2 files changed, 27 insertions(+), 23 deletions(-) diff --git a/app/components/voting-dapp/proposal-container.js b/app/components/voting-dapp/proposal-container.js index 74381f3..103f464 100644 --- a/app/components/voting-dapp/proposal-container.js +++ b/app/components/voting-dapp/proposal-container.js @@ -34,11 +34,7 @@ class ProposalContainer extends React.Component { // TODO: populate proposals let proposalList = [ { - description: "0x68747470733a2f2f69646561732e7374617475732e696d2f69646561732f3038382d646170702d657870657269656e6365", - approved: true - }, - { - description: "0x68747470733a2f2f69646561732e7374617475732e696d2f69646561732f3039302d6272616e63682d706572662d7374617473", + description: "QmZ4hQ5jKUqtHEXhXDVSz81JexMoDmVfiypECFQZZibyrS", approved: true } ] diff --git a/app/components/voting-dapp/proposal.js b/app/components/voting-dapp/proposal.js index 2898579..51e4b5d 100644 --- a/app/components/voting-dapp/proposal.js +++ b/app/components/voting-dapp/proposal.js @@ -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(//, ''); - 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 (
-

{ title }

+

{ this.state.title }

+

{ this.state.description }

{ this.state.url } -

{summary}

- - +
); }