Browse Source

북마크 기능 추가

yongun 5 năm trước cách đây
mục cha
commit
a12e1363d5
2 tập tin đã thay đổi với 11 bổ sung9 xóa
  1. 1 1
      pages/index.vue
  2. 10 8
      store/index.js

+ 1 - 1
pages/index.vue

@@ -204,7 +204,7 @@ export default {
   },
   async fetch ({ store }) {
     await store.dispatch('loadHeadLines', `/api/top-headlines?country=${store.state.country}&category=${store.state.category}`)
-    // await store.dispatch('loadUserFeed')
+    await store.dispatch('loadUserFeed')
   },
   methods: {
     async loadCategory (category) {

+ 10 - 8
store/index.js

@@ -84,15 +84,17 @@ const createStore = () => {
         await feedRef.set(headline)
       },
       async loadUserFeed ({ state, commit }) {
-        const feedRef = db.collection(`users/${state.user.email}/feed`)
-
-        await feedRef.get().then((querySnapshot) => {
-          const headlines = []
-          querySnapshot.forEach((doc) => {
-            headlines.push(doc.data())
+        if (state.user) {
+          const feedRef = db.collection(`users/${state.user.email}/feed`)
+          await feedRef.get().then((querySnapshot) => {
+            // eslint-disable-next-line prefer-const
+            let headlines = []
+            querySnapshot.forEach((doc) => {
+              headlines.push(doc.data())
+              commit('setFeed', headlines)
+            })
           })
-          commit('setFeed', headlines)
-        })
+        }
       },
       setLogoutTimer ({ dispatch }, interval) {
         setTimeout(() => dispatch('logoutUser'), interval)