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 => { const mapStateToProps = state => {
return { return {
user: state.user, user: state.user,
orbitDB: state.orbit, orbitDB: state.orbit
topicsDB: state.topicsDB
} }
} }

7
app/src/orbit.js

@ -39,7 +39,6 @@ async function createDatabases() {
topicsDB: topicsDB.address.root, topicsDB: topicsDB.address.root,
postsDB: postsDB.address.root postsDB: postsDB.address.root
}; };
console.dir(returnValue);
return 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 {call, select, take, takeEvery} from 'redux-saga/effects'
import { drizzle } from '../../index' import { drizzle } from '../../index'
import { orbitSagaPut } from '../../orbit'
let transactionsHistory = Object.create(null); let transactionsHistory = Object.create(null);
@ -26,11 +27,11 @@ function* handleEvent(action) {
//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
yield call([orbit.topicsDB, 'put'], [action.event.returnValues.topicID, yield call(orbitSagaPut, orbit.topicsDB, action.event.returnValues.topicID,
{ subject: transactionsHistory[dataKey].userInputs.topicSubject }]); { subject: transactionsHistory[dataKey].userInputs.topicSubject });
yield call([orbit.postsDB, 'put'], [action.event.returnValues.postID, yield call(orbitSagaPut, orbit.postsDB, 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; break;
case 'PostCreated': case 'PostCreated':
@ -41,9 +42,9 @@ function* handleEvent(action) {
//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
yield call([orbit.postsDB, 'put'], [action.event.returnValues.postID, yield call(orbitSagaPut, orbit.postsDB, action.event.returnValues.postID,
{subject: transactionsHistory[dataKey].userInputs.postSubject, {subject: transactionsHistory[dataKey].userInputs.postSubject,
content: transactionsHistory[dataKey].userInputs.postMessage }]); content: transactionsHistory[dataKey].userInputs.postMessage });
} }
break; break;
default: default:

Loading…
Cancel
Save