From 7cb1660a39520f75dc84faf369c7ce2609a403ce Mon Sep 17 00:00:00 2001 From: Gerald Michelant Date: Thu, 22 Nov 2018 17:36:01 -0500 Subject: [PATCH 1/2] fix deletion and update of comment refresh issue --- .env.example | 18 ------------------ components/Comments/Comment.vue | 2 +- store/comments.js | 18 ++++++++++++++++-- 3 files changed, 17 insertions(+), 21 deletions(-) delete mode 100644 .env.example diff --git a/.env.example b/.env.example deleted file mode 100644 index 0a3085cb..00000000 --- a/.env.example +++ /dev/null @@ -1,18 +0,0 @@ -# WEBAPP -WEBAPP_HOST = localhost -WEBAPP_PORT = 3000 -WEBAPP_BASE_URL = http://localhost:3000 - -# API -API_HOST = localhost -API_PORT = 3030 - -# METAAPI -EMBED_API_URL = http://localhost:3050 - -# 3rd party integrations -SENTRY_DNS_PUBLIC = -MAPBOX_TOKEN = pk.eyJ1IjoiaHVtYW4tY29ubmVjdGlvbiIsImEiOiJjajl0cnBubGoweTVlM3VwZ2lzNTNud3ZtIn0.KZ8KK9l70omjXbEkkbHGsQ - -# MAINTENANCE -MAINTENANCE = diff --git a/components/Comments/Comment.vue b/components/Comments/Comment.vue index 92f38c6c..07eef916 100644 --- a/components/Comments/Comment.vue +++ b/components/Comments/Comment.vue @@ -50,7 +50,7 @@ class="button is-hidden-mobile" color="light" :disabled="isLoading" - @click="cancelEdit"> + @click.prevent="cancelEdit"> {{ $t('button.cancel') }} comment._id === data._id)].contentExcerpt = data.content + }, + removeComment (state, id) { + const cmt = state.comments[state.comments.findIndex(comment => comment._id === id)] + console.log(cmt) + cmt.deleted = true } } @@ -111,10 +119,16 @@ export const actions = { create ({dispatch}, data) { return this.app.$api.service('comments').create(data) }, - patch ({dispatch}, data) { + patch ({commit}, data) { return this.app.$api.service('comments').patch(data._id, data) + .then(() => { + commit('updateComment', data) + }) }, - remove ({dispatch}, id) { + remove ({commit}, id) { return this.app.$api.service('comments').remove(id) + .then(() => { + commit('removeComment', id) + }) } } From 00f65698e295f05093a62aa4df2028b4311cdeb1 Mon Sep 17 00:00:00 2001 From: Gerald Michelant Date: Fri, 23 Nov 2018 10:03:08 -0500 Subject: [PATCH 2/2] changed method to update newContent with store instead of fetching --- components/Comments/Comment.vue | 9 +++------ store/comments.js | 10 ++++++---- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/components/Comments/Comment.vue b/components/Comments/Comment.vue index 07eef916..4e2a234d 100644 --- a/components/Comments/Comment.vue +++ b/components/Comments/Comment.vue @@ -140,7 +140,8 @@ computed: { ...mapGetters({ showComment: 'comments/showComment', - user: 'auth/user' + user: 'auth/user', + fetchById: 'comments/fetchById', }), getText () { return (this.fullContentShown && this.content) @@ -166,7 +167,6 @@ }, methods: { ...mapActions({ - fetchById: 'comments/fetchById', remove: 'comments/remove', patch: 'comments/patch' }), @@ -185,12 +185,9 @@ }) }, startEdit () { - this.fetchById(this.comment._id) - .then((res) => { - this.newContent = res.content + this.newContent = this.fetchById(this.comment._id).contentExcerpt this.edit = true this.fullContentShown = false; - }) }, cancelEdit () { this.edit = false diff --git a/store/comments.js b/store/comments.js index fe19f91f..a2024ff5 100644 --- a/store/comments.js +++ b/store/comments.js @@ -34,7 +34,6 @@ export const mutations = { }, removeComment (state, id) { const cmt = state.comments[state.comments.findIndex(comment => comment._id === id)] - console.log(cmt) cmt.deleted = true } } @@ -51,6 +50,9 @@ export const getters = { }, count (state) { return state.commentCount + }, + fetchById: (state) => (id) => { + return state.comments.find(comment => comment._id === id) } } @@ -104,9 +106,9 @@ export const actions = { commit('isLoading', false) }) }, - fetchById ({commit}, id) { - return this.app.$api.service('comments').get(id) - }, + // fetchById ({commit}, id) { + // return this.app.$api.service('comments').get(id) + // }, upvote ({dispatch}, comment) { return this.app.$api.service('comments').patch(comment._id, { $inc: {