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'" v-if="open === 'delete'"
:id="data.resource.id" :id="data.resource.id"
:type="data.type" :type="data.type"
:confirmCallback="data.callbacks.confirm" :confirm-callback="data.callbacks.confirm"
:cancelCallback="!!data.callbacks.cancel ? data.callbacks.cancel : null" :cancel-callback="!!data.callbacks.cancel ? data.callbacks.cancel : null"
:name="name" :name="name"
@close="close" @close="close"
/> />

View File

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

View File

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

View File

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

View File

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