First proof of functionality for Delete Comment and Post via DeleteModal

This commit is contained in:
Wolfgang Huß 2019-05-19 12:54:25 +02:00
parent 7f83f775a7
commit f5d9bc9ae4
5 changed files with 19 additions and 6 deletions

View File

@ -19,8 +19,8 @@
v-if="open === 'delete'"
:id="data.resource.id"
:type="data.type"
:confirmCallback="data.callbacks.confirm"
:cancelCallback="!!data.callbacks.cancel ? data.callbacks.cancel : null"
:confirm-callback="data.callbacks.confirm"
:cancel-callback="!!data.callbacks.cancel ? data.callbacks.cancel : null"
:name="name"
@close="close"
/>

View File

@ -84,9 +84,13 @@ export default {
}, 1000)
},
async confirm() {
console.log('"confirm" was reached !!!')
this.loading = true
try {
console.log('"confirmCallback" is: ', this.confirmCallback)
await this.confirmCallback()
// this.confirmCallback()
console.log('"confirmCallback" was exec !!!')
this.success = true
setTimeout(() => {
this.isOpen = false

View File

@ -2,7 +2,7 @@ import gql from 'graphql-tag'
export default {
methods: {
async deletePostCallback() {
async deletePostCallback(listPageType = true) {
try {
var gqlMutation = gql`
mutation($id: ID!) {
@ -16,7 +16,13 @@ export default {
variables: { id: this.post.id }
})
this.$toast.success(this.$t(`delete.contribution.success`))
this.$emit('deletePost')
if (listPageType) {
console.log('Emit "deletePost" !!!')
this.$emit('deletePost')
} else {
console.log('Redirect to index !!!')
this.$router.history.push('/') // Single page type: redirect to index
}
} catch (err) {
this.$toast.error(err.message)
}

View File

@ -87,7 +87,7 @@ export default {
})
},
deletePost(_index, postId) {
this.Post = this.Post.filter((post) => {
this.Post = this.Post.filter(post => {
return post.id !== postId
})
// Ideal solution:

View File

@ -18,7 +18,7 @@
placement="bottom-end"
resource-type="contribution"
:resource="post"
:callbacks="{ confirm: deletePostCallback, cancel: null }"
:callbacks="{ confirm: deletePostOptionsCallback, cancel: null }"
:is-owner="isAuthor(post.author.id)"
/>
</no-ssr>
@ -256,6 +256,9 @@ export default {
methods: {
isAuthor(id) {
return this.$store.getters['auth/user'].id === id
},
async deletePostOptionsCallback() {
await deletePostCallback(true)
}
}
}