From 29a4e2488151861c10abeb0a05622e4d06e07c60 Mon Sep 17 00:00:00 2001
From: Patryk Niedźwiedziński <pniedzwiedzinski19@gmail.com>
Date: Thu, 5 Dec 2019 17:34:44 +0100
Subject: Fix SSR on PostList

---
 components/Posts/PostList/PostList.vue | 45 +++++++++-------------------------
 1 file changed, 12 insertions(+), 33 deletions(-)

(limited to 'components/Posts/PostList/PostList.vue')

diff --git a/components/Posts/PostList/PostList.vue b/components/Posts/PostList/PostList.vue
index 781099f..80369a8 100644
--- a/components/Posts/PostList/PostList.vue
+++ b/components/Posts/PostList/PostList.vue
@@ -1,9 +1,8 @@
 <template>
-  <pure-post-list v-if="rawPosts" :posts="posts" :loading="loading" />
+  <pure-post-list v-if="posts" :posts="parsedPosts" :loading="loading" />
 </template>
 
 <script>
-import k from '~/api'
 import PurePostList from './PurePostList'
 
 export default {
@@ -12,43 +11,23 @@ export default {
   props: {
     max: {
       type: Number,
+      required: false,
+      default: () => 4
+    },
+    posts: {
+      type: Array,
       required: false
     }
   },
-  data() {
-    return {
-      loading: true,
-      rawPosts: undefined
-    }
-  },
-  mounted() {
-    if (process.client && this.rawPosts === undefined) {
-      this.loadPostsClient()
-    } else {
-      this.rawPosts = k.getPosts()
-      this.loading = false
-    }
-  },
   computed: {
-    posts() {
+    parsedPosts() {
       if (this.max) {
-        return this.rawPosts.slice(0, this.max)
+        return this.posts.slice(0, this.max)
       }
-      return this.rawPosts
-    }
-  },
-  methods: {
-    async loadPostsClient() {
-      let posts = await this.$axios.get(
-        `${window.location.origin}/api/posts.json`
-      )
-      this.rawPosts = posts.data
-      this.rawPosts = this.rawPosts.map(post => ({
-        title: post.content.meta.title,
-        description: post.content.description,
-        route: post.route
-      }))
-      this.loading = false
+      return this.posts
+    },
+    loading() {
+      return this.posts === undefined
     }
   }
 }
-- 
cgit 1.4.1

