Browse Source

Add transactionsSaga case for posting, Minor fix

develop
Apostolos Fanakis 6 years ago
parent
commit
c1f58cd20e
  1. 8
      app/src/components/NewPost.js
  2. 21
      app/src/redux/sagas/transactionsSaga.js

8
app/src/components/NewPost.js

@ -7,7 +7,7 @@ import TimeAgo from 'react-timeago';
import UserAvatar from 'react-user-avatar'; import UserAvatar from 'react-user-avatar';
import ReactMarkdown from 'react-markdown'; import ReactMarkdown from 'react-markdown';
/*import { createPost } from '../redux/actions/transactionsMonitorActions';*/ import { createPost } from '../redux/actions/transactionsActions';
class NewPost extends Component { class NewPost extends Component {
constructor(props, context) { constructor(props, context) {
@ -25,7 +25,7 @@ class NewPost extends Component {
postSubjectInputEmptySubmit: false, postSubjectInputEmptySubmit: false,
postContentInputEmptySubmit: false, postContentInputEmptySubmit: false,
previewEnabled: false, previewEnabled: false,
previewDate: "" previewDate: ''
}; };
} }
@ -38,14 +38,14 @@ class NewPost extends Component {
return; return;
} }
/*this.props.store.dispatch( this.props.dispatch(
createPost(this.props.topicID, createPost(this.props.topicID,
{ {
postSubject: this.state.postSubjectInput, postSubject: this.state.postSubjectInput,
postMessage: this.state.postContentInput postMessage: this.state.postContentInput
} }
) )
);*/ );
this.props.onPostCreated(); this.props.onPostCreated();
} }

21
app/src/redux/sagas/transactionsSaga.js

@ -7,20 +7,22 @@ let transactionsHistory = Object.create(null);
function* initTransaction(action) { function* initTransaction(action) {
var dataKey = drizzle.contracts[action.transactionDescriptor.contract] var dataKey = drizzle.contracts[action.transactionDescriptor.contract]
.methods[action.transactionDescriptor['method']] .methods[action.transactionDescriptor['method']]
.cacheSend(...[action.transactionDescriptor.params]); .cacheSend(...(action.transactionDescriptor.params));
transactionsHistory[dataKey] = action; transactionsHistory[dataKey] = action;
transactionsHistory[dataKey].state = 'initialized'; transactionsHistory[dataKey].state = 'initialized';
} }
function* handleEvent(action) { function* handleEvent(action) {
switch(action.event.event) {
case 'TopicCreated':
var transactionStack = yield select((state) => state.transactionStack); var transactionStack = yield select((state) => state.transactionStack);
var dataKey = transactionStack.indexOf(action.event.transactionHash); var dataKey = transactionStack.indexOf(action.event.transactionHash);
switch(action.event.event) {
case 'TopicCreated':
if (dataKey !== -1 && if (dataKey !== -1 &&
transactionsHistory[dataKey] && transactionsHistory[dataKey] &&
transactionsHistory[dataKey].state === 'initialized') { transactionsHistory[dataKey].state === 'initialized') {
transactionsHistory[dataKey].state = 'success';
//Gets orbit //Gets orbit
const orbit = yield select((state) => state.orbit); const orbit = yield select((state) => state.orbit);
//And saves the topic //And saves the topic
@ -29,8 +31,19 @@ function* handleEvent(action) {
yield call([orbit.postsDB, 'put'], [action.event.returnValues.postID, yield call([orbit.postsDB, 'put'], [action.event.returnValues.postID,
{subject: transactionsHistory[dataKey].userInputs.topicSubject, {subject: transactionsHistory[dataKey].userInputs.topicSubject,
content: transactionsHistory[dataKey].userInputs.topicMessage }]); content: transactionsHistory[dataKey].userInputs.topicMessage }]);
}
break;
case 'PostCreated':
if (dataKey !== -1 &&
transactionsHistory[dataKey] &&
transactionsHistory[dataKey].state === 'initialized') {
transactionsHistory[dataKey].state = 'success'; 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; break;
default: default:

Loading…
Cancel
Save