|
@@ -80,6 +80,10 @@ const createStore = () => {
|
|
|
// console.log(error)
|
|
|
}
|
|
|
},
|
|
|
+ async removeHeadlineFromFeed ({ state }, headline) {
|
|
|
+ const headlineRef = db.collection(`users/${state.user.email}/feed`).doc(headline.title)
|
|
|
+ await headlineRef.delete()
|
|
|
+ },
|
|
|
async addHeadlineToFeed ({ state }, headline) {
|
|
|
const feedRef = db.collection(`users/${state.user.email}/feed`).doc(headline.title)
|
|
|
await feedRef.set(headline)
|
|
@@ -87,14 +91,19 @@ const createStore = () => {
|
|
|
async loadUserFeed ({ state, commit }) {
|
|
|
if (state.user) {
|
|
|
const feedRef = db.collection(`users/${state.user.email}/feed`)
|
|
|
- // feedRef.onSnapshot now work
|
|
|
- await feedRef.get().then((querySnapshot) => {
|
|
|
+
|
|
|
+ await feedRef.onSnapshot((querySnapshot) => {
|
|
|
// eslint-disable-next-line prefer-const
|
|
|
let headlines = []
|
|
|
querySnapshot.forEach((doc) => {
|
|
|
headlines.push(doc.data())
|
|
|
commit('setFeed', headlines)
|
|
|
})
|
|
|
+
|
|
|
+ if (querySnapshot.empty) {
|
|
|
+ headlines = []
|
|
|
+ commit('setFeed', headlines)
|
|
|
+ }
|
|
|
})
|
|
|
}
|
|
|
},
|