Skip to content

Commit

Permalink
fix: redux keeps initialising the list over an over
Browse files Browse the repository at this point in the history
this fixes #71
we've just undone our first initialize list once and add it to a TODO for later

Co-authored-by: Filip Cornel-Cristian <[email protected]>
Co-authored-by: Dorin Dumitrascuta <[email protected]>
  • Loading branch information
3 people committed Jul 20, 2019
1 parent 02a3cc1 commit 708286e
Showing 1 changed file with 29 additions and 13 deletions.
42 changes: 29 additions & 13 deletions src/component/web-data/web-data.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,43 @@ const WebData = () => {

useEffect(() => {
// I want to get a list of courses from FireStore
const unsubscribe = db
const courseCollection = db
.collection('course')

// TODO, create some sort of initialising only once
// or check if an element exists by id, or whatever
// works so you get the list once and on snapshot change
// only adds the first ones if the list hasn't been initialised.
// const courseList = snapList.docs.map(d => {
// return {
// id: d.id,
// ...d.data()
// }
// })

// dispatch(initCourseListAction(courseList))
// courseCollection.get().then((snapList => {
// }))
const unsubscribe = courseCollection
.onSnapshot(snapList => {
const courseList = snapList.docs.map(d => {
return {
id: d.id,
...d.data()
}
})
// const courseList = snapList.docs.map(d => {
// return {
// id: d.id,
// ...d.data()
// }
// })

dispatch(initCourseListAction(courseList))
// dispatch(initCourseListAction(courseList))

snapList.docChanges().forEach(change => {
const course = change.doc.data()
// console.log(title, change.type, change.doc.id)
if (change.type === 'added') {
// dispatch(addCourseAction({
// title: course.title,
// description: course.description,
// id: change.doc.id,
// }))
dispatch(addCourseAction({
title: course.title,
description: course.description,
id: change.doc.id,
}))
}
else if (change.type === 'removed') {
dispatch(removeCourseAction({
Expand Down

0 comments on commit 708286e

Please sign in to comment.