chore: remove prompts events

pull/1307/head
Ramires Viana 2021-03-04 14:40:18 +00:00
parent edb9e85efd
commit 2a1f759e9e
4 changed files with 31 additions and 42 deletions

View File

@ -26,7 +26,7 @@ export default {
name: 'delete', name: 'delete',
computed: { computed: {
...mapGetters(['isListing', 'selectedCount']), ...mapGetters(['isListing', 'selectedCount']),
...mapState(['req', 'selected']) ...mapState(['req', 'selected', 'showConfirm'])
}, },
methods: { methods: {
...mapMutations(['closeHovers']), ...mapMutations(['closeHovers']),
@ -38,7 +38,7 @@ export default {
await api.remove(this.$route.path) await api.remove(this.$route.path)
buttons.success('delete') buttons.success('delete')
this.$root.$emit('preview-deleted') this.showConfirm()
this.closeHovers() this.closeHovers()
return return
} }

View File

@ -1,7 +1,7 @@
<template> <template>
<div class="card floating"> <div class="card floating">
<div class="card-content"> <div class="card-content">
<p>{{ $t('prompts.deleteMessageShare', {path: hash.path}) }}</p> <p>{{ $t('prompts.deleteMessageShare', {path: ''}) }}</p>
</div> </div>
<div class="card-action"> <div class="card-action">
<button @click="$store.commit('closeHovers')" <button @click="$store.commit('closeHovers')"
@ -17,30 +17,16 @@
</template> </template>
<script> <script>
import {mapMutations, mapState} from 'vuex' import {mapState} from 'vuex'
import { share as api } from '@/api'
import buttons from '@/utils/buttons'
export default { export default {
name: 'share-delete', name: 'share-delete',
computed: { computed: {
...mapState(['hash']) ...mapState(['showConfirm'])
}, },
methods: { methods: {
...mapMutations(['closeHovers']), submit: function () {
submit: async function () { this.showConfirm()
buttons.loading('delete')
try {
await api.remove(this.hash.hash)
buttons.success('delete')
this.$root.$emit('share-deleted', this.hash.hash)
this.closeHovers()
} catch (e) {
buttons.done('delete')
this.$showError(e)
}
} }
} }
} }

View File

@ -7,7 +7,7 @@
<template #actions> <template #actions>
<action :disabled="loading" icon="mode_edit" :label="$t('buttons.rename')" show="rename" /> <action :disabled="loading" icon="mode_edit" :label="$t('buttons.rename')" show="rename" />
<action :disabled="loading" icon="delete" :label="$t('buttons.delete')" show="delete" /> <action :disabled="loading" icon="delete" :label="$t('buttons.delete')" @action="deleteFile" id="delete-button" />
<action :disabled="loading" icon="file_download" :label="$t('buttons.download')" @action="download" /> <action :disabled="loading" icon="file_download" :label="$t('buttons.download')" @action="download" />
<action :disabled="loading" icon="info" :label="$t('buttons.info')" show="info" /> <action :disabled="loading" icon="info" :label="$t('buttons.info')" show="info" />
</template> </template>
@ -126,24 +126,27 @@ export default {
async mounted () { async mounted () {
window.addEventListener('keydown', this.key) window.addEventListener('keydown', this.key)
this.listing = this.oldReq.items this.listing = this.oldReq.items
this.$root.$on('preview-deleted', this.deleted)
this.updatePreview() this.updatePreview()
}, },
beforeDestroy () { beforeDestroy () {
window.removeEventListener('keydown', this.key) window.removeEventListener('keydown', this.key)
this.$root.$off('preview-deleted', this.deleted)
}, },
methods: { methods: {
deleted () { deleteFile () {
this.listing = this.listing.filter(item => item.name !== this.name) this.$store.commit('showHover', {
prompt: 'delete',
confirm: () => {
this.listing = this.listing.filter(item => item.name !== this.name)
if (this.hasNext) { if (this.hasNext) {
this.next() this.next()
} else if (!this.hasPrevious && !this.hasNext) { } else if (!this.hasPrevious && !this.hasNext) {
this.close() this.close()
} else { } else {
this.prev() this.prev()
} }
}
})
}, },
prev () { prev () {
this.hoverNav = false this.hoverNav = false

View File

@ -77,23 +77,23 @@ export default {
this.clip.on('success', () => { this.clip.on('success', () => {
this.$showSuccess(this.$t('success.linkCopied')) this.$showSuccess(this.$t('success.linkCopied'))
}) })
this.$root.$on('share-deleted', this.deleted)
}, },
beforeDestroy () { beforeDestroy () {
this.clip.destroy() this.clip.destroy()
this.$root.$off('share-deleted', this.deleted)
}, },
methods: { methods: {
deleteLink: async function (event, link) { deleteLink: async function (event, link) {
event.preventDefault() event.preventDefault()
this.$store.commit('setHash', {
hash: link.hash, this.$store.commit('showHover', {
path: link.path prompt: 'share-delete',
confirm: () => {
this.$store.commit('closeHovers')
api.remove(link.hash)
this.links = this.links.filter(item => item.hash !== link.hash)
}
}) })
this.$store.commit('showHover', 'share-delete')
},
deleted (hash) {
this.links = this.links.filter(item => item.hash !== hash)
}, },
humanTime (time) { humanTime (time) {
return moment(time * 1000).fromNow() return moment(time * 1000).fromNow()