fix(files): Close sidebar if shown node is deleted

Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
This commit is contained in:
Ferdinand Thiessen 2024-04-17 17:03:21 +02:00
parent c750ed66a7
commit 3c74559e4c
No known key found for this signature in database
GPG key ID: 45FAE7268762B400

View file

@ -105,7 +105,7 @@
import { getCurrentUser } from '@nextcloud/auth'
import { getCapabilities } from '@nextcloud/capabilities'
import { showError } from '@nextcloud/dialogs'
import { emit } from '@nextcloud/event-bus'
import { emit, subscribe, unsubscribe } from '@nextcloud/event-bus'
import { File, Folder, formatFileSize } from '@nextcloud/files'
import { encodePath } from '@nextcloud/paths'
import { generateRemoteUrl, generateUrl } from '@nextcloud/router'
@ -304,10 +304,13 @@ export default {
},
},
created() {
subscribe('files:node:deleted', this.onNodeDeleted)
window.addEventListener('resize', this.handleWindowResize)
this.handleWindowResize()
},
beforeDestroy() {
unsubscribe('file:node:deleted', this.onNodeDeleted)
window.removeEventListener('resize', this.handleWindowResize)
},
@ -507,6 +510,16 @@ export default {
this.resetData()
},
/**
* Handle if the current node was deleted
* @param {import('@nextcloud/files').Node} node The deleted node
*/
onNodeDeleted(node) {
if (this.fileInfo && node && this.fileInfo.id === node.fileid) {
this.close()
}
},
/**
* Allow to set the Sidebar as fullscreen from OCA.Files.Sidebar
*