Browse Source

Do not lose previously fetched values on orbit update

develop
Apostolos Fanakis 4 years ago
parent
commit
262719ee61
  1. 38
      packages/concordia-app/src/redux/sagas/peerDbReplicationSaga.js

38
packages/concordia-app/src/redux/sagas/peerDbReplicationSaga.js

@ -25,25 +25,45 @@ function* updateReduxState({ database }) {
})); }));
if (database.dbname === 'topics') { if (database.dbname === 'topics') {
const oldTopicsUnchanged = topics
.filter((topic) => !Object
.keys(database.all)
.map((key) => parseInt(key, 10))
.includes(topic.id));
yield put({ yield put({
type: UPDATE_ORBIT_DATA, type: UPDATE_ORBIT_DATA,
topics: [...Object.entries(database.all).map(([key, value]) => ({ topics: [
id: parseInt(key, 10), ...oldTopicsUnchanged,
subject: value.subject, ...Object
}))], .entries(database.all)
.map(([key, value]) => ({
id: parseInt(key, 10),
subject: value.subject,
})),
],
posts: [...posts], posts: [...posts],
}); });
} }
if (database.dbname === 'posts') { if (database.dbname === 'posts') {
const oldPostsUnchanged = posts
.filter((post) => !Object
.keys(database.all)
.map((key) => parseInt(key, 10))
.includes(post.id));
yield put({ yield put({
type: UPDATE_ORBIT_DATA, type: UPDATE_ORBIT_DATA,
topics: [...topics], topics: [...topics],
posts: [...Object.entries(database.all).map(([key, value]) => ({ posts: [
id: parseInt(key, 10), ...oldPostsUnchanged,
subject: value.subject, ...Object.entries(database.all).map(([key, value]) => ({
message: value.message, id: parseInt(key, 10),
}))], subject: value.subject,
message: value.message,
})),
],
}); });
} }
} }

Loading…
Cancel
Save