From 070b7725be5fb0db486e9370bea5648c16c8bbfe Mon Sep 17 00:00:00 2001
From: Patryk Niedźwiedziński <pniedzwiedzinski19@gmail.com>
Date: Sat, 30 Nov 2019 13:12:30 +0100
Subject: Fix posts listing

---
 pages/kronika/index.vue | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

(limited to 'pages/kronika/index.vue')

diff --git a/pages/kronika/index.vue b/pages/kronika/index.vue
index 4a89a48..d28c2ca 100644
--- a/pages/kronika/index.vue
+++ b/pages/kronika/index.vue
@@ -1,7 +1,7 @@
 <template>
   <div style="padding-top: 20px">
     <h2>Ostatnie wpisy</h2>
-    <div class="post-list">
+    <div v-if="posts" class="post-list">
       <chronicle-post
         v-for="(post, index) in posts"
         :key="index"
@@ -23,20 +23,20 @@ export default {
   },
   async asyncData() {
     return {
-      posts: k.getPosts()
+      posts: process.client ? undefined : k.getPosts()
     }
   },
   mounted() {
-    this.getPosts()
+    if (process.client && this.posts === undefined) {
+      this.getPosts().then(posts => (this.posts = posts))
+    }
   },
   methods: {
-    getPosts() {
-      if (this.posts.length < 1) {
-        this.$axios
-          .get(`${window.location.origin}/api/posts.json`)
-          .then(r => (this.posts = r.data))
-      }
-      console.log(this.posts)
+    async getPosts() {
+      const r = await this.$axios.get(
+        `${window.location.origin}/api/posts.json`
+      )
+      return r.data
     }
   }
 }
-- 
cgit 1.4.1

