diff --git a/app/src/components/NewPost.js b/app/src/components/NewPost.js index 59d79bc..72001ba 100644 --- a/app/src/components/NewPost.js +++ b/app/src/components/NewPost.js @@ -7,7 +7,7 @@ import TimeAgo from 'react-timeago'; import UserAvatar from 'react-user-avatar'; import ReactMarkdown from 'react-markdown'; -/*import { createPost } from '../redux/actions/transactionsMonitorActions';*/ +import { createPost } from '../redux/actions/transactionsActions'; class NewPost extends Component { constructor(props, context) { @@ -25,7 +25,7 @@ class NewPost extends Component { postSubjectInputEmptySubmit: false, postContentInputEmptySubmit: false, previewEnabled: false, - previewDate: "" + previewDate: '' }; } @@ -38,14 +38,14 @@ class NewPost extends Component { return; } - /*this.props.store.dispatch( + this.props.dispatch( createPost(this.props.topicID, { postSubject: this.state.postSubjectInput, postMessage: this.state.postContentInput } ) - );*/ + ); this.props.onPostCreated(); } diff --git a/app/src/redux/sagas/transactionsSaga.js b/app/src/redux/sagas/transactionsSaga.js index 4f2e3c0..2c28c88 100644 --- a/app/src/redux/sagas/transactionsSaga.js +++ b/app/src/redux/sagas/transactionsSaga.js @@ -7,20 +7,22 @@ let transactionsHistory = Object.create(null); function* initTransaction(action) { var dataKey = drizzle.contracts[action.transactionDescriptor.contract] .methods[action.transactionDescriptor['method']] - .cacheSend(...[action.transactionDescriptor.params]); + .cacheSend(...(action.transactionDescriptor.params)); transactionsHistory[dataKey] = action; transactionsHistory[dataKey].state = 'initialized'; } function* handleEvent(action) { + var transactionStack = yield select((state) => state.transactionStack); + var dataKey = transactionStack.indexOf(action.event.transactionHash); + switch(action.event.event) { case 'TopicCreated': - var transactionStack = yield select((state) => state.transactionStack); - var dataKey = transactionStack.indexOf(action.event.transactionHash); if (dataKey !== -1 && transactionsHistory[dataKey] && transactionsHistory[dataKey].state === 'initialized') { + transactionsHistory[dataKey].state = 'success'; //Gets orbit const orbit = yield select((state) => state.orbit); //And saves the topic @@ -29,8 +31,19 @@ function* handleEvent(action) { yield call([orbit.postsDB, 'put'], [action.event.returnValues.postID, {subject: transactionsHistory[dataKey].userInputs.topicSubject, content: transactionsHistory[dataKey].userInputs.topicMessage }]); - + } + break; + case 'PostCreated': + if (dataKey !== -1 && + transactionsHistory[dataKey] && + transactionsHistory[dataKey].state === 'initialized') { transactionsHistory[dataKey].state = 'success'; + //Gets orbit + const orbit = yield select((state) => state.orbit); + //And saves the topic + yield call([orbit.postsDB, 'put'], [action.event.returnValues.postID, + {subject: transactionsHistory[dataKey].userInputs.postSubject, + content: transactionsHistory[dataKey].userInputs.postMessage }]); } break; default: