20.04 Read Data - When Task Added

This commit is contained in:
Fredrick W. Warren 2021-02-15 07:25:01 -08:00
parent b86f2bc0cf
commit 7378e2391a

View File

@ -1,6 +1,6 @@
import Vue from 'vue'
import { uid } from 'quasar'
import { databaseDb } from 'boot/firebase'
import { firebaseDb, firebaseAuth } from 'boot/firebase'
const state = {
tasks: {
@ -69,7 +69,18 @@ const actions = {
commit('setSort', value)
},
fbReadData ({ commit }) {
console.log('read data from database')
const userId = firebaseAuth.currentUser.uid
const userTasks = firebaseDb.ref('tasks/' + userId)
// child added
userTasks.on('child_added', snapshot => {
const task = snapshot.val()
const payload = {
id: snapshot.key,
task: task
}
commit('addTask', payload)
})
}
}