Skip to content

Commit

Permalink
Adjust page icon delete implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Fajfa committed Oct 19, 2023
1 parent 46b06e9 commit a97ef7c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 26 deletions.
56 changes: 31 additions & 25 deletions client/web/compose/src/views/Admin/Pages/Edit.vue
Original file line number Diff line number Diff line change
Expand Up @@ -735,20 +735,21 @@
:title="$t('icon.configure')"
size="lg"
label-class="text-primary"
footer-class="d-flex justify-content-between"
footer-class="d-flex align-items-center"
no-fade
>
<template #modal-footer>
<c-input-confirm
:disabled="(attachments && !selectedAttachmentID) || processing"
v-if="attachments && selectedAttachmentID"
:disabled="(attachments && !selectedAttachmentID) || processingIcon"
size="md"
variant="danger"
class="py-1"
@confirmed="deleteIcon"
>
{{ $t('icon.delete') }}
</c-input-confirm>
<div>

<div class="ml-auto">
<b-button
variant="link"
class="text-primary"
Expand All @@ -758,6 +759,7 @@
</b-button>
<b-button
variant="primary"
class="ml-2"
@click="saveIconModal"
>
{{ $t('general:label.saveAndClose') }}
Expand Down Expand Up @@ -810,7 +812,7 @@
label-class="text-primary"
>
<div
v-if="processing"
v-if="processingIcon"
class="d-flex align-items-center justify-content-center h-100"
>
<b-spinner />
Expand Down Expand Up @@ -938,6 +940,7 @@ export default {
data () {
return {
processing: false,
processingIcon: false,
page: new compose.Page(),
initialPageState: new compose.Page(),
Expand Down Expand Up @@ -1266,7 +1269,7 @@ export default {
},
async fetchAttachments () {
this.processing = true
this.processingIcon = true
return this.$ComposeAPI.iconList({ sort: 'id DESC' })
.then(({ set: attachments = [] }) => {
Expand All @@ -1284,7 +1287,7 @@ export default {
})
.catch(this.toastErrorHandler(this.$t('notification:page.iconFetchFailed')))
.finally(() => {
this.processing = false
this.processingIcon = false
})
},
Expand Down Expand Up @@ -1332,12 +1335,33 @@ export default {
this.showIconModal = false
},
deleteIcon () {
this.processingIcon = true
return this.$ComposeAPI.iconDelete({ iconID: this.selectedAttachmentID }).then(() => {
return this.fetchAttachments().then(() => {
this.setCurrentIcon()
this.toastSuccess(this.$t('notification:page.iconDeleteSuccess'))
})
}).finally(() => {
this.processingIcon = false
}).catch(this.toastErrorHandler(this.$t('notification:page.iconDeleteFailed')))
},
closeIconModal () {
this.linkUrl = this.icon.type === 'link' ? this.icon.src : ''
this.setCurrentIcon()
this.showIconModal = false
},
setCurrentIcon () {
this.selectedAttachmentID = (this.attachments.find(a => a.url === this.icon.src) || {}).attachmentID
if (!this.selectedAttachmentID) {
this.icon = {}
}
},
makeAttachmentUrl (src) {
return `${this.$ComposeAPI.baseURL}${src}`
},
Expand Down Expand Up @@ -1378,24 +1402,6 @@ export default {
cancel()
})
},
deleteIcon () {
return this.$ComposeAPI.iconDelete({ iconID: this.selectedAttachmentID })
.then(() => {
this.fetchAttachments().then(() => {
this.setCurrentIcon()
})
})
.catch(this.toastErrorHandler(this.$t('notification:page.iconUndeleteFailed')))
},
setCurrentIcon () {
this.selectedAttachmentID = (this.attachments.find(a => a.url === this.icon.src) || {}).attachmentID
if (!this.selectedAttachmentID) {
this.icon = {}
}
},
},
}
</script>
Expand Down
3 changes: 2 additions & 1 deletion locale/en/corteza-webapp-compose/notification.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ page:
cloneFailed: Could not clone this page
deleteFailed: Could not delete this page
iconFetchFailed: Could not fetch list of icons
iconUndeleteFailed: Could not delete selected icon
iconDeleteFailed: Could not delete selected icon
iconDeleteSuccess: Icon deleted
loadFailed: Could not load the page tree
noPages: No pages found
saveFailed: Could not save this page
Expand Down

0 comments on commit a97ef7c

Please sign in to comment.