diff --git a/backend/src/seed/factories/comments.js b/backend/src/seed/factories/comments.js index b30cede36..ba3a85840 100644 --- a/backend/src/seed/factories/comments.js +++ b/backend/src/seed/factories/comments.js @@ -19,6 +19,6 @@ export default function (params) { } } `, - variables: { id, content } + variables: { id, postId, content } } } diff --git a/webapp/graphql/PostQuery.gql b/webapp/graphql/PostQuery.gql new file mode 100644 index 000000000..87021b7ee --- /dev/null +++ b/webapp/graphql/PostQuery.gql @@ -0,0 +1,66 @@ +query Post($slug: String!) { + Post(slug: $slug) { + id + title + content + createdAt + disabled + deleted + slug + image + author { + id + slug + name + avatar + disabled + deleted + shoutedCount + contributionsCount + commentsCount + followedByCount + followedByCurrentUser + badges { + id + key + icon + } + } + tags { + name + } + commentsCount + comments(orderBy: createdAt_desc) { + id + contentExcerpt + createdAt + disabled + deleted + author { + id + slug + name + avatar + disabled + deleted + shoutedCount + contributionsCount + commentsCount + followedByCount + followedByCurrentUser + badges { + id + key + icon + } + } + } + categories { + id + name + icon + } + shoutedCount + shoutedByCurrentUser + } +} diff --git a/webapp/pages/post/_id/_slug/index.vue b/webapp/pages/post/_id/_slug/index.vue index 95295d6bf..fc0056e0b 100644 --- a/webapp/pages/post/_id/_slug/index.vue +++ b/webapp/pages/post/_id/_slug/index.vue @@ -131,7 +131,7 @@ @@ -172,7 +172,8 @@ import HcUser from '~/components/User' import HcShoutButton from '~/components/ShoutButton.vue' import HcEmpty from '~/components/Empty.vue' import Comment from '~/components/Comment.vue' -import HcEditor from '~/components/Editor/Editor.vue' +import HcEditor from '~/components/Editor' +import POST_INFO from '~/graphql/PostQuery.gql' export default { transition: { @@ -316,7 +317,12 @@ export default { isAuthor(id) { return this.$store.getters['auth/user'].id === id }, + addComment(comment) { + this.post.comments.push(comment) + }, handleSubmit() { + const value = this.value + this.value = '' this.loading = true this.$apollo .mutate({ @@ -330,10 +336,33 @@ export default { `, variables: { postId: this.post.id, - content: this.value - } - }) + content: value + }, + update: (store, { data: { CreateComment } }) => { + const data = store.readQuery({ query: POST_INFO }) + // data.Post.push(CreateComment) + // store.writeQuery({ query: POST_INFO, data }) + // // Add to Todo tasks list + // const todoQuery = { + // query: POST_INFO, + // variables: { filter: { done: false } }, + // } + // const todoData = store.readQuery(todoQuery) + // todoData.allTasks.push(createTask) + // store.writeQuery({ ...todoQuery, data: todoData }) + }, + optimisticResponse: { + __typename: 'Mutation', + CreateComment: { + __typename: 'Comment', + id: null, + content: value + }, + }, + }) .then(res => { + console.log(res.data.CreateComment) + this.addComment(res.data.CreateComment) this.disabled = true this.loading = false this.$toast.success('Saved!')