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') {
const oldTopicsUnchanged = topics
.filter((topic) => !Object
.keys(database.all)
.map((key) => parseInt(key, 10))
.includes(topic.id));
yield put({
type: UPDATE_ORBIT_DATA,
topics: [...Object.entries(database.all).map(([key, value]) => ({
id: parseInt(key, 10),
subject: value.subject,
}))],
topics: [
...oldTopicsUnchanged,
...Object
.entries(database.all)
.map(([key, value]) => ({
id: parseInt(key, 10),
subject: value.subject,
})),
],
posts: [...posts],
});
}
if (database.dbname === 'posts') {
const oldPostsUnchanged = posts
.filter((post) => !Object
.keys(database.all)
.map((key) => parseInt(key, 10))
.includes(post.id));
yield put({
type: UPDATE_ORBIT_DATA,
topics: [...topics],
posts: [...Object.entries(database.all).map(([key, value]) => ({
id: parseInt(key, 10),
subject: value.subject,
message: value.message,
}))],
posts: [
...oldPostsUnchanged,
...Object.entries(database.all).map(([key, value]) => ({
id: parseInt(key, 10),
subject: value.subject,
message: value.message,
})),
],
});
}
}

Loading…
Cancel
Save