From 40f5b6acd5545dcbf8a5bc60abed29cf9b2bb435 Mon Sep 17 00:00:00 2001 From: Matt Rider Date: Thu, 2 May 2019 21:03:31 -0300 Subject: [PATCH] Extract CommentsList component - this allows to Query for comments by Post --- webapp/components/CommentForm/index.vue | 2 +- webapp/components/CommentList/index.vue | 79 +++++++++++++++++++++++++ webapp/graphql/PostCommentsQuery.js | 40 +++++++++++++ webapp/pages/post/_id/_slug/index.vue | 62 ++----------------- 4 files changed, 125 insertions(+), 58 deletions(-) create mode 100644 webapp/components/CommentList/index.vue create mode 100644 webapp/graphql/PostCommentsQuery.js diff --git a/webapp/components/CommentForm/index.vue b/webapp/components/CommentForm/index.vue index fdb1761dc..6019b0965 100644 --- a/webapp/components/CommentForm/index.vue +++ b/webapp/components/CommentForm/index.vue @@ -91,7 +91,7 @@ export default { } }) .then(res => { - this.$emit('addComment', res.data.CreateComment) + this.$root.$emit('addComment', res.data.CreateComment) this.$refs.editor.clear() this.$toast.success(this.$t('post.comment.submitted')) }) diff --git a/webapp/components/CommentList/index.vue b/webapp/components/CommentList/index.vue new file mode 100644 index 000000000..ba9ada717 --- /dev/null +++ b/webapp/components/CommentList/index.vue @@ -0,0 +1,79 @@ + + diff --git a/webapp/graphql/PostCommentsQuery.js b/webapp/graphql/PostCommentsQuery.js new file mode 100644 index 000000000..2c37f2933 --- /dev/null +++ b/webapp/graphql/PostCommentsQuery.js @@ -0,0 +1,40 @@ +import gql from 'graphql-tag' + +export default app => { + const lang = app.$i18n.locale().toUpperCase() + return gql(` + query Post($slug: String!) { + Post(slug: $slug) { + commentsCount + comments(orderBy: createdAt_asc) { + id + contentExcerpt + createdAt + disabled + deleted + author { + id + slug + name + avatar + disabled + deleted + shoutedCount + contributionsCount + commentsCount + followedByCount + followedByCurrentUser + location { + name: name${lang} + } + badges { + id + key + icon + } + } + } + } + } + `) +} diff --git a/webapp/pages/post/_id/_slug/index.vue b/webapp/pages/post/_id/_slug/index.vue index 7ae683425..692dbe69e 100644 --- a/webapp/pages/post/_id/_slug/index.vue +++ b/webapp/pages/post/_id/_slug/index.vue @@ -96,39 +96,9 @@ -

- - - {{ comments.length }}  Comments - -

+ -
- -
- - - +
@@ -142,9 +112,8 @@ import HcTag from '~/components/Tag' import ContentMenu from '~/components/ContentMenu' import HcUser from '~/components/User' import HcShoutButton from '~/components/ShoutButton.vue' -import HcEmpty from '~/components/Empty.vue' import HcCommentForm from '~/components/CommentForm' -import Comment from '~/components/Comment.vue' +import HcCommentList from '~/components/CommentList' export default { transition: { @@ -156,10 +125,9 @@ export default { HcCategory, HcUser, HcShoutButton, - HcEmpty, - Comment, ContentMenu, - HcCommentForm + HcCommentForm, + HcCommentList }, head() { return { @@ -169,7 +137,6 @@ export default { data() { return { post: null, - comments: null, ready: false, title: 'loading' } @@ -178,9 +145,6 @@ export default { Post(post) { this.post = post[0] || {} this.title = this.post.title - }, - Comment(comments) { - this.comments = comments || [] } }, async asyncData(context) { @@ -289,22 +253,6 @@ export default { methods: { isAuthor(id) { return this.$store.getters['auth/user'].id === id - }, - addComment(comment) { - this.$apollo.queries.Comment.refetch() - } - }, - apollo: { - Comment: { - query() { - return require('~/graphql/CommentQuery.js').default(this) - }, - variables() { - return { - postId: this.post.id - } - }, - fetchPolicy: 'cache-and-network' } } }