about summary refs log tree commit diff
path: root/components/Posts/PostList/PostList.vue
diff options
context:
space:
mode:
authorPatryk Niedźwiedziński <pniedzwiedzinski19@gmail.com>2019-12-05 17:34:44 +0100
committerPatryk Niedźwiedziński <pniedzwiedzinski19@gmail.com>2019-12-05 17:34:44 +0100
commit29a4e2488151861c10abeb0a05622e4d06e07c60 (patch)
treec237820ce1f7588d44820f64163bc0caaa693d7f /components/Posts/PostList/PostList.vue
parent6a532274bf7d69cefe9e640274f30c3fdcc17c92 (diff)
downloadpuszcza-29a4e2488151861c10abeb0a05622e4d06e07c60.tar.gz
puszcza-29a4e2488151861c10abeb0a05622e4d06e07c60.zip
Fix SSR on PostList
Diffstat (limited to 'components/Posts/PostList/PostList.vue')
-rw-r--r--components/Posts/PostList/PostList.vue45
1 files changed, 12 insertions, 33 deletions
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
     }
   }
 }