about summary refs log tree commit diff
path: root/components/Posts
diff options
context:
space:
mode:
Diffstat (limited to 'components/Posts')
-rw-r--r--components/Posts/PostList/PostList.vue6
-rw-r--r--components/Posts/PostList/PurePostList.vue16
-rw-r--r--components/Posts/PostList/index.js9
-rw-r--r--components/Posts/PostList/parentMixin.js9
4 files changed, 31 insertions, 9 deletions
diff --git a/components/Posts/PostList/PostList.vue b/components/Posts/PostList/PostList.vue
index 80369a8..64070d8 100644
--- a/components/Posts/PostList/PostList.vue
+++ b/components/Posts/PostList/PostList.vue
@@ -1,5 +1,5 @@
 <template>
-  <pure-post-list v-if="posts" :posts="parsedPosts" :loading="loading" />
+  <pure-post-list v-if="posts" :next="next" :posts="parsedPosts" :loading="loading" />
 </template>
 
 <script>
@@ -17,6 +17,10 @@ export default {
     posts: {
       type: Array,
       required: false
+    },
+    next: {
+      type: Number,
+      required: false
     }
   },
   computed: {
diff --git a/components/Posts/PostList/PurePostList.vue b/components/Posts/PostList/PurePostList.vue
index 7281f21..b152dda 100644
--- a/components/Posts/PostList/PurePostList.vue
+++ b/components/Posts/PostList/PurePostList.vue
@@ -14,6 +14,9 @@
           :description="post.description"
           :image="post.meta.image"
         />
+        <nuxt-link :to="`?page=${next}`" v-if="next">
+          <plain-button class="next-link" text="Wcześniejsze wpisy"/>
+        </nuxt-link>
       </div>
     </transition>
   </div>
@@ -21,15 +24,20 @@
 
 <script>
 import PostLink from '../PostLink'
+import PlainButton from '../../Buttons/PlainButton.vue';
 
 export default {
   name: 'PurePostList',
-  components: { PostLink },
+  components: { PostLink, PlainButton },
   props: {
     posts: {
       type: Array,
       required: true,
     },
+    next: {
+      type: Number,
+      required: false,
+    },
     loading: {
       type: Boolean,
       required: false,
@@ -84,6 +92,12 @@ export default {
   text-align: center;
 }
 
+.next-link {
+  margin: 2em 0;
+  padding: 1em;
+  max-width: 100%;
+}
+
 @keyframes fade-in {
   0% {
     opacity: 1;
diff --git a/components/Posts/PostList/index.js b/components/Posts/PostList/index.js
index dad805d..d3ca5f7 100644
--- a/components/Posts/PostList/index.js
+++ b/components/Posts/PostList/index.js
@@ -3,9 +3,12 @@ import axios from 'axios'
 import { apiUrl, parsePosts } from '~/api'
 import PostList from './PostList'
 
-export const getPosts = async () => {
-  let posts = await axios.get(`${apiUrl}/posts.json`)
-  return parsePosts(posts.data)
+export const getPosts = async (pageId) => {
+  let { data } = await axios.get(`${apiUrl}/page/${pageId}.json`)
+  return {
+    posts: parsePosts(data.posts),
+    next: data.next
+  };
 }
 
 export default PostList
diff --git a/components/Posts/PostList/parentMixin.js b/components/Posts/PostList/parentMixin.js
index 801d51c..b9181e8 100644
--- a/components/Posts/PostList/parentMixin.js
+++ b/components/Posts/PostList/parentMixin.js
@@ -1,9 +1,10 @@
 import { getPosts } from './index'
 
 export default {
-  async asyncData() {
-    return {
-      posts: await getPosts(),
-    }
+  async asyncData({ query }) {
+    let page = query.page || 1;
+    const data = await getPosts(page);
+    return data;
   },
+  watchQuery: true
 }