mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-13 07:46:06 +00:00
made load more a component and added it to the newsfeed too
This commit is contained in:
parent
5561cda13e
commit
201b02ac1d
21
components/LoadMore.vue
Normal file
21
components/LoadMore.vue
Normal file
@ -0,0 +1,21 @@
|
||||
<template>
|
||||
<ds-space
|
||||
margin-top="large"
|
||||
style="text-align: center">
|
||||
<ds-button
|
||||
:icon="loading ? 'spinner' : 'arrow-down'"
|
||||
:disabled="loading"
|
||||
ghost
|
||||
@click="$emit('click')">
|
||||
mehr laden
|
||||
</ds-button>
|
||||
</ds-space>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
props: {
|
||||
loading: { type: Boolean, default: false }
|
||||
}
|
||||
}
|
||||
</script>
|
||||
@ -1,7 +1,7 @@
|
||||
import gql from 'graphql-tag'
|
||||
|
||||
export default gql(`
|
||||
query User($slug: String!, $offset: Int, $first: Int) {
|
||||
query User($slug: String!, $first: Int, $offset: Int) {
|
||||
User(slug: $slug) {
|
||||
id
|
||||
name
|
||||
|
||||
@ -1,33 +1,46 @@
|
||||
<template>
|
||||
<ds-flex
|
||||
:width="{ base: '100%' }"
|
||||
gutter="base">
|
||||
<ds-flex-item
|
||||
v-for="post in Post"
|
||||
:width="{ base: '100%', xs: '100%', md: '50%', xl: '33%' }"
|
||||
:key="post.id">
|
||||
<hc-post-card :post="post" />
|
||||
</ds-flex-item>
|
||||
</ds-flex>
|
||||
<div>
|
||||
<ds-flex
|
||||
:width="{ base: '100%' }"
|
||||
gutter="base">
|
||||
<ds-flex-item
|
||||
v-for="post in Post"
|
||||
:width="{ base: '100%', xs: '100%', md: '50%', xl: '33%' }"
|
||||
:key="post.id">
|
||||
<hc-post-card :post="post" />
|
||||
</ds-flex-item>
|
||||
</ds-flex>
|
||||
<hc-load-more
|
||||
v-if="true"
|
||||
:loading="$apollo.loading"
|
||||
@click="showMoreContributions" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import gql from 'graphql-tag'
|
||||
import HcPostCard from '~/components/PostCard.vue'
|
||||
import HcLoadMore from '~/components/LoadMore.vue'
|
||||
|
||||
export default {
|
||||
components: {
|
||||
HcPostCard
|
||||
HcPostCard,
|
||||
HcLoadMore
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
// Initialize your apollo data
|
||||
Post: []
|
||||
Post: [],
|
||||
page: 1,
|
||||
pageSize: 10
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
tags() {
|
||||
return this.Post ? this.Post[0].tags.map(tag => tag.name) : '-'
|
||||
},
|
||||
offset() {
|
||||
return (this.page - 1) * this.pageSize
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
@ -36,13 +49,31 @@ export default {
|
||||
name: 'post-slug',
|
||||
params: { slug: post.slug }
|
||||
}).href
|
||||
},
|
||||
showMoreContributions() {
|
||||
// this.page++
|
||||
// Fetch more data and transform the original result
|
||||
this.page++
|
||||
this.$apollo.queries.Post.fetchMore({
|
||||
variables: {
|
||||
first: this.pageSize,
|
||||
offset: this.offset
|
||||
},
|
||||
// Transform the previous result with new data
|
||||
updateQuery: (previousResult, { fetchMoreResult }) => {
|
||||
let output = { Post: this.Post }
|
||||
output.Post = [...previousResult.Post, ...fetchMoreResult.Post]
|
||||
return output
|
||||
},
|
||||
fetchPolicy: 'cache-and-network'
|
||||
})
|
||||
}
|
||||
},
|
||||
apollo: {
|
||||
Post: {
|
||||
query: gql(`
|
||||
query {
|
||||
Post(first:10) {
|
||||
query Post($first: Int, $offset: Int) {
|
||||
Post(first: $first, offset: $offset) {
|
||||
id
|
||||
title
|
||||
contentExcerpt
|
||||
@ -74,7 +105,13 @@ export default {
|
||||
shoutedCount
|
||||
}
|
||||
}
|
||||
`)
|
||||
`),
|
||||
variables() {
|
||||
return {
|
||||
first: this.pageSize,
|
||||
offset: 0
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -187,18 +187,10 @@
|
||||
:show-author-popover="false" />
|
||||
</ds-flex-item>
|
||||
</ds-flex>
|
||||
<ds-space
|
||||
<hc-load-more
|
||||
v-if="hasMore"
|
||||
margin-top="large"
|
||||
style="text-align: center">
|
||||
<ds-button
|
||||
:icon="$apollo.loading ? 'spinner' : 'arrow-down'"
|
||||
:disabled="$apollo.loading"
|
||||
ghost
|
||||
@click="showMoreContributions">
|
||||
mehr laden
|
||||
</ds-button>
|
||||
</ds-space>
|
||||
:loading="$apollo.loading"
|
||||
@click="showMoreContributions" />
|
||||
</ds-flex-item>
|
||||
</ds-flex>
|
||||
</div>
|
||||
@ -212,6 +204,7 @@ import HcPostCard from '~/components/PostCard.vue'
|
||||
import HcFollowButton from '~/components/FollowButton.vue'
|
||||
import HcCountTo from '~/components/CountTo.vue'
|
||||
import HcBadges from '~/components/Badges.vue'
|
||||
import HcLoadMore from '~/components/LoadMore.vue'
|
||||
|
||||
export default {
|
||||
components: {
|
||||
@ -219,7 +212,8 @@ export default {
|
||||
HcPostCard,
|
||||
HcFollowButton,
|
||||
HcCountTo,
|
||||
HcBadges
|
||||
HcBadges,
|
||||
HcLoadMore
|
||||
},
|
||||
transition: {
|
||||
name: 'slide-up',
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user