Skip to content

Commit 9515cee

Browse files
authored
feat: automatically jump to the next photo when deleting while previewing (filebrowser#1143)
1 parent e8b4e9a commit 9515cee

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

frontend/src/components/files/Preview.vue

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,16 +133,29 @@ export default {
133133
}
134134
},
135135
async mounted () {
136-
window.addEventListener('keyup', this.key)
136+
window.addEventListener('keydown', this.key)
137137
this.$store.commit('setPreviewMode', true)
138138
this.listing = this.oldReq.items
139+
this.$root.$on('preview-deleted', this.deleted)
139140
this.updatePreview()
140141
},
141142
beforeDestroy () {
142-
window.removeEventListener('keyup', this.key)
143+
window.removeEventListener('keydown', this.key)
143144
this.$store.commit('setPreviewMode', false)
145+
this.$root.$off('preview-deleted', this.deleted)
144146
},
145147
methods: {
148+
deleted () {
149+
this.listing = this.listing.filter(item => item.name !== this.name)
150+
151+
if (this.hasNext) {
152+
this.next()
153+
} else if (!this.hasPrevious && !this.hasNext) {
154+
this.back()
155+
} else {
156+
this.prev()
157+
}
158+
},
146159
back () {
147160
this.$store.commit('setPreviewMode', false)
148161
let uri = url.removeLastDir(this.$route.path) + '/'
@@ -155,7 +168,6 @@ export default {
155168
this.$router.push({ path: this.nextLink })
156169
},
157170
key (event) {
158-
event.preventDefault()
159171
160172
if (this.show !== null) {
161173
return

frontend/src/components/prompts/Delete.vue

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
<script>
2121
import {mapGetters, mapMutations, mapState} from 'vuex'
2222
import { files as api } from '@/api'
23-
import url from '@/utils/url'
2423
import buttons from '@/utils/buttons'
2524
2625
export default {
@@ -32,17 +31,20 @@ export default {
3231
methods: {
3332
...mapMutations(['closeHovers']),
3433
submit: async function () {
35-
this.closeHovers()
3634
buttons.loading('delete')
3735
3836
try {
3937
if (!this.isListing) {
4038
await api.remove(this.$route.path)
4139
buttons.success('delete')
42-
this.$router.push({ path: url.removeLastDir(this.$route.path) + '/' })
40+
41+
this.$root.$emit('preview-deleted')
42+
this.closeHovers()
4343
return
4444
}
4545
46+
this.closeHovers()
47+
4648
if (this.selectedCount === 0) {
4749
return
4850
}

0 commit comments

Comments
 (0)