From 6f861ebd6d778b41112983868b8c9514a9b839e5 Mon Sep 17 00:00:00 2001 From: Apostolof Date: Fri, 8 Jun 2018 23:12:52 +0300 Subject: [PATCH] Improve contract interaction, Rebase, Minor style changes --- package.json | 1 + src/assets/css/App.css | 2 +- src/components/StartTopic.js | 200 ----------------- src/components/TopicList.js | 2 +- src/containers/BoardContainer.js | 42 ++-- src/containers/StartTopicContainer.js | 297 ++++++++++++++++++++++++++ src/index.js | 2 + 7 files changed, 320 insertions(+), 226 deletions(-) delete mode 100644 src/components/StartTopic.js create mode 100644 src/containers/StartTopicContainer.js diff --git a/package.json b/package.json index e674ce3..c463321 100644 --- a/package.json +++ b/package.json @@ -27,6 +27,7 @@ "react-user-avatar": "^1.10.0", "redux": "^3.7.2", "redux-saga": "0.16.0", + "uuid": "^3.2.1", "web3": "^1.0.0-beta.34" }, "scripts": { diff --git a/src/assets/css/App.css b/src/assets/css/App.css index d87580a..781c76f 100644 --- a/src/assets/css/App.css +++ b/src/assets/css/App.css @@ -170,7 +170,7 @@ body, } .topic-form textarea { - height: 200px; + min-height: 200px; } .form-input-required { diff --git a/src/components/StartTopic.js b/src/components/StartTopic.js deleted file mode 100644 index 464eda5..0000000 --- a/src/components/StartTopic.js +++ /dev/null @@ -1,200 +0,0 @@ -import { drizzleConnect } from 'drizzle-react' -import React, { Component } from 'react' -import PropTypes from 'prop-types' - -import Post from './Post' - -const contract = "Forum"; -const contractMethod = "createTopic"; - -class StartTopic extends Component { - constructor(props, context) { - super(props); - - this.handleInputChange = this.handleInputChange.bind(this); - this.handlePreviewToggle = this.handlePreviewToggle.bind(this); - this.validateAndPost = this.validateAndPost.bind(this); - this.pushToDatabase = this.pushToDatabase.bind(this); - - this.transactionProgressText = []; - this.drizzle = context.drizzle; - - this.state = { - topicSubjectInput: '', - topicMessageInput: '', - topicSubjectInputEmptySubmit: false, - topicMessageInputEmptySubmit: false, - previewEnabled: false, - previewDate: "", - creatingTopic: false, - transactionState: null, - savingToOrbitDB: null - }; - } - - async validateAndPost() { - if (this.state.topicSubjectInput === '' || this.state.topicMessageInput === ''){ - this.setState({ - topicSubjectInputEmptySubmit: this.state.topicSubjectInput === '', - topicMessageInputEmptySubmit: this.state.topicMessageInput === '' - }); - return; - } - - this.stackId = this.drizzle.contracts[contract].methods[contractMethod].cacheSend(); - this.transactionProgressText.push(
); - this.transactionProgressText.push("Waiting for transaction acceptance..."); - this.setState({ - 'creatingTopic': true, - 'transactionState': "ACCEPTANCE_PENDING" - }); - } - - async pushToDatabase() { - await this.props.orbitDB.topicsDB.put(this.topicIDFetched, { - subject: this.state.topicSubjectInput, - content: this.state.topicMessageInput - }); - this.setState({'savingToOrbitDB': "SUCCESS"}); - } - - handleInputChange(event) { - this.setState({[event.target.name]: event.target.value}); - } - - handlePreviewToggle() { - this.setState((prevState, props) => ({ - previewEnabled: !prevState.previewEnabled, - previewDate: this.getDate() - })); - } - - getDate() { - const currentdate = new Date(); - return ((currentdate.getMonth() + 1) + " " - + currentdate.getDate() + ", " - + currentdate.getFullYear() + ", " - + currentdate.getHours() + ":" - + currentdate.getMinutes() + ":" - + currentdate.getSeconds()); - } - - render() { - return( -
- {this.state.creatingTopic &&
-
-

-
- {this.transactionProgressText} -
-
- } -
-

- -

-
- {this.state.previewEnabled && - } -
- {!this.state.previewEnabled && - [ - , -