mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-13 07:46:06 +00:00
added pagination to profile
This commit is contained in:
parent
7cc53d7426
commit
f1824d7c06
@ -1,7 +1,7 @@
|
|||||||
import gql from 'graphql-tag'
|
import gql from 'graphql-tag'
|
||||||
|
|
||||||
export default gql(`
|
export default gql(`
|
||||||
query User($slug: String!) {
|
query User($slug: String!, $offset: Int, $first: Int) {
|
||||||
User(slug: $slug) {
|
User(slug: $slug) {
|
||||||
id
|
id
|
||||||
name
|
name
|
||||||
@ -52,7 +52,7 @@ export default gql(`
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
contributionsCount
|
contributionsCount
|
||||||
contributions(first: 6) {
|
contributions(first: $first, offset: $offset) {
|
||||||
id
|
id
|
||||||
slug
|
slug
|
||||||
title
|
title
|
||||||
|
|||||||
@ -15,11 +15,18 @@
|
|||||||
:name="user.name || 'Anonymus'"
|
:name="user.name || 'Anonymus'"
|
||||||
class="profile-avatar"
|
class="profile-avatar"
|
||||||
size="120px" />
|
size="120px" />
|
||||||
<h3 style="text-align: center;">{{ user.name }}</h3>
|
<ds-space margin="small">
|
||||||
<hc-badges
|
<ds-heading
|
||||||
|
tag="h3"
|
||||||
|
align="center"
|
||||||
|
no-margin>{{ user.name }}</ds-heading>
|
||||||
|
</ds-space>
|
||||||
|
<ds-space
|
||||||
v-if="user.badges && user.badges.length"
|
v-if="user.badges && user.badges.length"
|
||||||
:badges="user.badges"
|
margin="x-small">
|
||||||
style="margin-top: -5px" />
|
<hc-badges
|
||||||
|
:badges="user.badges" />
|
||||||
|
</ds-space>
|
||||||
<ds-flex>
|
<ds-flex>
|
||||||
<ds-flex-item>
|
<ds-flex-item>
|
||||||
<no-ssr>
|
<no-ssr>
|
||||||
@ -181,11 +188,13 @@
|
|||||||
</ds-flex-item>
|
</ds-flex-item>
|
||||||
</ds-flex>
|
</ds-flex>
|
||||||
<ds-space
|
<ds-space
|
||||||
|
v-if="hasMore"
|
||||||
margin-top="large"
|
margin-top="large"
|
||||||
style="text-align: center">
|
style="text-align: center">
|
||||||
<ds-button
|
<ds-button
|
||||||
icon="arrow-down"
|
icon="arrow-down"
|
||||||
ghost>
|
ghost
|
||||||
|
@click="showMoreContributions">
|
||||||
mehr laden
|
mehr laden
|
||||||
</ds-button>
|
</ds-button>
|
||||||
</ds-space>
|
</ds-space>
|
||||||
@ -216,7 +225,9 @@ export default {
|
|||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
User: [],
|
User: [],
|
||||||
voted: false
|
voted: false,
|
||||||
|
page: 1,
|
||||||
|
pageSize: 6
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
@ -233,6 +244,15 @@ export default {
|
|||||||
},
|
},
|
||||||
user() {
|
user() {
|
||||||
return this.User ? this.User[0] : {}
|
return this.User ? this.User[0] : {}
|
||||||
|
},
|
||||||
|
offset() {
|
||||||
|
return (this.page - 1) * this.pageSize
|
||||||
|
},
|
||||||
|
hasMore() {
|
||||||
|
return (
|
||||||
|
this.user.contributions &&
|
||||||
|
this.user.contributions.length < this.user.contributionsCount
|
||||||
|
)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
@ -246,6 +266,27 @@ export default {
|
|||||||
fetchUser() {
|
fetchUser() {
|
||||||
// TODO: we should use subscriptions instead of fetching the whole user again
|
// TODO: we should use subscriptions instead of fetching the whole user again
|
||||||
this.$apollo.queries.User.refetch()
|
this.$apollo.queries.User.refetch()
|
||||||
|
},
|
||||||
|
showMoreContributions() {
|
||||||
|
// this.page++
|
||||||
|
// Fetch more data and transform the original result
|
||||||
|
this.page++
|
||||||
|
this.$apollo.queries.User.fetchMore({
|
||||||
|
variables: {
|
||||||
|
slug: this.$route.params.slug,
|
||||||
|
first: this.pageSize,
|
||||||
|
offset: this.offset
|
||||||
|
},
|
||||||
|
// Transform the previous result with new data
|
||||||
|
updateQuery: (previousResult, { fetchMoreResult }) => {
|
||||||
|
let output = { User: this.User }
|
||||||
|
output.User[0].contributions = [
|
||||||
|
...previousResult.User[0].contributions,
|
||||||
|
...fetchMoreResult.User[0].contributions
|
||||||
|
]
|
||||||
|
return output
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
apollo: {
|
apollo: {
|
||||||
@ -253,7 +294,9 @@ export default {
|
|||||||
query: require('~/graphql/UserProfileQuery.js').default,
|
query: require('~/graphql/UserProfileQuery.js').default,
|
||||||
variables() {
|
variables() {
|
||||||
return {
|
return {
|
||||||
slug: this.$route.params.slug
|
slug: this.$route.params.slug,
|
||||||
|
first: this.pageSize,
|
||||||
|
offset: 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user