Automatically jumps to the next photo when deleting while previewing.

This commit is contained in:
chief 2020-11-08 16:00:09 -05:00
parent dcbc3286e2
commit 4972a7ea17
4 changed files with 51 additions and 4 deletions

View File

@ -62,7 +62,7 @@
</template> </template>
<script> <script>
import { mapState } from 'vuex' import { mapMutations, mapState } from 'vuex'
import url from '@/utils/url' import url from '@/utils/url'
import { baseURL, resizePreview } from '@/utils/constants' import { baseURL, resizePreview } from '@/utils/constants'
import { files as api } from '@/api' import { files as api } from '@/api'
@ -143,8 +143,16 @@ export default {
this.$store.commit('setPreviewMode', false) this.$store.commit('setPreviewMode', false)
}, },
methods: { methods: {
...mapMutations([
'setPostDeletionLink',
'setCurrentListingIndex',
'setDeletionOccurred'
]),
back () { back () {
this.$store.commit('setPreviewMode', false) this.$store.commit('setPreviewMode', false)
this.setPostDeletionLink(null)
this.setCurrentListingIndex(-1)
this.setDeletionOccurred(false)
let uri = url.removeLastDir(this.$route.path) + '/' let uri = url.removeLastDir(this.$route.path) + '/'
this.$router.push({ path: uri }) this.$router.push({ path: uri })
}, },
@ -188,11 +196,20 @@ export default {
this.previousLink = '' this.previousLink = ''
this.nextLink = '' this.nextLink = ''
// Before continuing, splice out the prior current index if a deletion
// occurred.
if (this.$store.state.deletionOccurred) {
this.listing.splice(this.$store.state.currentListingIndex, 1)
this.setDeletionOccurred(false)
}
for (let i = 0; i < this.listing.length; i++) { for (let i = 0; i < this.listing.length; i++) {
if (this.listing[i].name !== this.name) { if (this.listing[i].name !== this.name) {
continue continue
} }
this.setCurrentListingIndex(i)
for (let j = i - 1; j >= 0; j--) { for (let j = i - 1; j >= 0; j--) {
if (mediaTypes.includes(this.listing[j].type)) { if (mediaTypes.includes(this.listing[j].type)) {
this.previousLink = this.listing[j].url this.previousLink = this.listing[j].url
@ -200,9 +217,12 @@ export default {
} }
} }
this.setPostDeletionLink(null)
for (let j = i + 1; j < this.listing.length; j++) { for (let j = i + 1; j < this.listing.length; j++) {
if (mediaTypes.includes(this.listing[j].type)) { if (mediaTypes.includes(this.listing[j].type)) {
this.nextLink = this.listing[j].url this.nextLink = this.listing[j].url
this.setPostDeletionLink(this.nextLink)
break break
} }
} }

View File

@ -30,7 +30,11 @@ export default {
...mapState(['req', 'selected']) ...mapState(['req', 'selected'])
}, },
methods: { methods: {
...mapMutations(['closeHovers']), ...mapMutations([
'closeHovers',
'setPostDeletionLink',
'setDeletionOccurred'
]),
submit: async function () { submit: async function () {
this.closeHovers() this.closeHovers()
buttons.loading('delete') buttons.loading('delete')
@ -39,7 +43,18 @@ export default {
if (!this.isListing) { if (!this.isListing) {
await api.remove(this.$route.path) await api.remove(this.$route.path)
buttons.success('delete') buttons.success('delete')
this.$router.push({ path: url.removeLastDir(this.$route.path) + '/' }) let path = url.removeLastDir(this.$route.path) + '/'
// Indicate a deletion occurred to ensure the current index gets
// spliced out in Preview.vue.
this.setDeletionOccurred(true)
// Jump to the next listing item, if there is one.
if (this.$store.state.postDeletionLink != null) {
path = this.$store.state.postDeletionLink;
}
this.$router.push({ path: path })
return return
} }

View File

@ -24,7 +24,10 @@ const state = {
showShell: false, showShell: false,
showMessage: null, showMessage: null,
showConfirm: null, showConfirm: null,
previewMode: false previewMode: false,
postDeletionLink: null,
currentListingIndex: -1,
deletionOccurred: false
} }
export default new Vuex.Store({ export default new Vuex.Store({

View File

@ -86,6 +86,15 @@ const mutations = {
}, },
setPreviewMode(state, value) { setPreviewMode(state, value) {
state.previewMode = value state.previewMode = value
},
setPostDeletionLink: (state, value) => {
state.postDeletionLink = value
},
setCurrentListingIndex: (state, value) => {
state.currentListingIndex = value
},
setDeletionOccurred: (state, value) => {
state.deletionOccurred = value
} }
} }