diff options
author | Patryk Niedźwiedziński <pniedzwiedzinski19@gmail.com> | 2021-01-10 12:31:02 +0100 |
---|---|---|
committer | Patryk Niedźwiedziński <pniedzwiedzinski19@gmail.com> | 2021-01-10 12:31:02 +0100 |
commit | ed9e80f161f6c99228595bc9dab9897469de224c (patch) | |
tree | 8b1bf8ffdce5f5d8e4f7f2d8ac49269dd3d4672a /components | |
parent | ebb089825a57c1fee04f8b2c0ea43447c07deeb6 (diff) | |
download | puszcza-ed9e80f161f6c99228595bc9dab9897469de224c.tar.gz puszcza-ed9e80f161f6c99228595bc9dab9897469de224c.zip |
Add pagination
Diffstat (limited to 'components')
-rw-r--r-- | components/Posts/PostList/PostList.vue | 6 | ||||
-rw-r--r-- | components/Posts/PostList/PurePostList.vue | 16 | ||||
-rw-r--r-- | components/Posts/PostList/index.js | 9 | ||||
-rw-r--r-- | components/Posts/PostList/parentMixin.js | 9 |
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 } |