output uniqe users and posts on profile page

This commit is contained in:
Grzegorz Leoniec 2018-10-26 16:10:12 +02:00
parent 1af35ea4cf
commit 5561cda13e

View File

@ -74,7 +74,7 @@
</ds-space> </ds-space>
<template v-if="user.following && user.following.length"> <template v-if="user.following && user.following.length">
<ds-space <ds-space
v-for="follow in user.following" v-for="follow in uniq(user.following)"
:key="follow.id" :key="follow.id"
margin="x-small"> margin="x-small">
<!-- TODO: find better solution for rendering errors --> <!-- TODO: find better solution for rendering errors -->
@ -109,7 +109,7 @@
</ds-space> </ds-space>
<template v-if="user.followedBy && user.followedBy.length"> <template v-if="user.followedBy && user.followedBy.length">
<ds-space <ds-space
v-for="follow in user.followedBy" v-for="follow in uniq(user.followedBy)"
:key="follow.id" :key="follow.id"
margin="x-small"> margin="x-small">
<!-- TODO: find better solution for rendering errors --> <!-- TODO: find better solution for rendering errors -->
@ -179,7 +179,7 @@
</ds-card> </ds-card>
</ds-flex-item> </ds-flex-item>
<ds-flex-item <ds-flex-item
v-for="post in user.contributions.filter(post => !post.deleted)" v-for="post in uniq(user.contributions.filter(post => !post.deleted))"
:width="{ base: '100%', md: '100%', xl: '50%' }" :width="{ base: '100%', md: '100%', xl: '50%' }"
:key="post.id"> :key="post.id">
<hc-post-card <hc-post-card
@ -205,6 +205,8 @@
</template> </template>
<script> <script>
import uniqBy from 'lodash/uniqBy'
import HcRelatedUser from '~/components/RelatedUser.vue' import HcRelatedUser from '~/components/RelatedUser.vue'
import HcPostCard from '~/components/PostCard.vue' import HcPostCard from '~/components/PostCard.vue'
import HcFollowButton from '~/components/FollowButton.vue' import HcFollowButton from '~/components/FollowButton.vue'
@ -264,6 +266,9 @@ export default {
} }
}, },
methods: { methods: {
uniq(items, field = 'id') {
return uniqBy(items, field)
},
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()