Browse Source

OrbitDB put fix for sagas

develop
Apostolos Fanakis 6 years ago
parent
commit
955c2d78ee
  1. 3
      app/src/components/Topic.js
  2. 7
      app/src/orbit.js
  3. 15
      app/src/redux/sagas/transactionsSaga.js

3
app/src/components/Topic.js

@ -97,8 +97,7 @@ class Topic extends Component {
const mapStateToProps = state => {
return {
user: state.user,
orbitDB: state.orbit,
topicsDB: state.topicsDB
orbitDB: state.orbit
}
}

7
app/src/orbit.js

@ -39,7 +39,6 @@ async function createDatabases() {
topicsDB: topicsDB.address.root,
postsDB: postsDB.address.root
};
console.dir(returnValue);
return returnValue;
}
@ -71,4 +70,8 @@ async function loadDatabases(identityId, identityPublicKey, identityPrivateKey,
});
}
export { initIPFS, createDatabases, loadDatabases };
async function orbitSagaPut(db, key, value) {
db.put(key, value);
}
export { initIPFS, createDatabases, loadDatabases, orbitSagaPut };

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

@ -1,6 +1,7 @@
import {call, select, take, takeEvery} from 'redux-saga/effects'
import { drizzle } from '../../index'
import { orbitSagaPut } from '../../orbit'
let transactionsHistory = Object.create(null);
@ -26,11 +27,11 @@ function* handleEvent(action) {
//Gets orbit
const orbit = yield select((state) => state.orbit);
//And saves the topic
yield call([orbit.topicsDB, 'put'], [action.event.returnValues.topicID,
{ subject: transactionsHistory[dataKey].userInputs.topicSubject }]);
yield call([orbit.postsDB, 'put'], [action.event.returnValues.postID,
{subject: transactionsHistory[dataKey].userInputs.topicSubject,
content: transactionsHistory[dataKey].userInputs.topicMessage }]);
yield call(orbitSagaPut, orbit.topicsDB, action.event.returnValues.topicID,
{ subject: transactionsHistory[dataKey].userInputs.topicSubject });
yield call(orbitSagaPut, orbit.postsDB, action.event.returnValues.postID,
{ subject: transactionsHistory[dataKey].userInputs.topicSubject,
content: transactionsHistory[dataKey].userInputs.topicMessage });
}
break;
case 'PostCreated':
@ -41,9 +42,9 @@ function* handleEvent(action) {
//Gets orbit
const orbit = yield select((state) => state.orbit);
//And saves the topic
yield call([orbit.postsDB, 'put'], [action.event.returnValues.postID,
yield call(orbitSagaPut, orbit.postsDB, action.event.returnValues.postID,
{subject: transactionsHistory[dataKey].userInputs.postSubject,
content: transactionsHistory[dataKey].userInputs.postMessage }]);
content: transactionsHistory[dataKey].userInputs.postMessage });
}
break;
default:

Loading…
Cancel
Save