Investigation how to update the Comments List intelligent

This commit is contained in:
Wolfgang Huß 2019-05-18 07:35:45 +02:00
parent a9617c8b62
commit 8033556145
4 changed files with 41 additions and 7 deletions

View File

@ -19,6 +19,7 @@
<content-menu <content-menu
placement="bottom-end" placement="bottom-end"
resource-type="comment" resource-type="comment"
:deleteCallback="deleteCallback"
:resource="comment" :resource="comment"
style="float-right" style="float-right"
:is-owner="isAuthor(author.id)" :is-owner="isAuthor(author.id)"
@ -69,6 +70,9 @@ export default {
methods: { methods: {
isAuthor(id) { isAuthor(id) {
return this.user.id === id return this.user.id === id
},
deleteCallback() {
console.log('"deleteCallback" was called !!!')
} }
} }
} }

View File

@ -18,6 +18,7 @@
v-if="open === 'delete'" v-if="open === 'delete'"
:id="data.resource.id" :id="data.resource.id"
:type="data.type" :type="data.type"
:deleteCallback="deleteCallback"
:name="name" :name="name"
@close="close" @close="close"
/> />
@ -37,6 +38,10 @@ export default {
ReportModal, ReportModal,
DeleteModal DeleteModal
}, },
props: {
deleteCallback: { type: Function, required: true },
cancelCallback: { type: Function, default: null }
},
computed: { computed: {
...mapGetters({ ...mapGetters({
data: 'modal/data', data: 'modal/data',

View File

@ -53,6 +53,8 @@ export default {
props: { props: {
name: { type: String, default: '' }, name: { type: String, default: '' },
type: { type: String, required: true }, type: { type: String, required: true },
deleteCallback: { type: Function, required: true },
cancelCallback: { type: Function, default: null },
id: { type: String, required: true } id: { type: String, required: true }
}, },
data() { data() {
@ -116,12 +118,23 @@ export default {
setTimeout(() => { setTimeout(() => {
this.success = false this.success = false
this.$emit('close') this.$emit('close')
if (this.$router.history.current.name === 'post-id-slug') { switch (this.type) {
// redirect to index case 'contribution':
this.$router.history.push('/') if (this.$router.history.current.name === 'post-id-slug') {
} else { // redirect to index
// reload the page (when deleting from profile or index) this.$router.history.push('/')
window.location.assign(window.location.href) } else {
// reload the page (when deleting from profile or index)
window.location.assign(window.location.href)
}
break
case 'comment':
// reload the page
// window.location.assign(window.location.href)
console.log('Remove comment emit !!!')
// this.$parent.$parent.$emit('deleteComment')
this.deleteCallback()
break
} }
}, 500) }, 500)
}, 1500) }, 1500)

View File

@ -19,10 +19,18 @@
class="comments" class="comments"
> >
<comment <comment
v-for="comment in comments" v-for="(comment, index) in comments"
:key="comment.id" :key="comment.id"
:comment="comment" :comment="comment"
@deleteComment="deleteComment(index)"
/> />
<!-- <comment
is="comment-item"
v-for="(comment, index) in comments"
:key="comment.id"
:comment="comment"
v-on:remove="comments.splice(index, 1)"
/> -->
</div> </div>
<hc-empty <hc-empty
v-else v-else
@ -61,6 +69,10 @@ export default {
methods: { methods: {
refetchPostComments(comment) { refetchPostComments(comment) {
this.$apollo.queries.Post.refetch() this.$apollo.queries.Post.refetch()
},
deleteComment(index) {
console.log('Remove comment event !!!')
this.comments.splice(index, 1)
} }
}, },
apollo: { apollo: {