aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLouis Chemineau <louis@chmn.me>2024-09-16 11:10:31 +0200
committerLouis Chemineau <louis@chmn.me>2024-09-16 11:59:34 +0200
commit936f34d3a5bb12181608574ed5db0e1ce1c919c3 (patch)
treef2a02312c1a609027e8f3a849fa908654decd504
parentbbe3b99254192f4093c667ce4ff12a2e68463472 (diff)
downloadnextcloud-server-936f34d3a5bb12181608574ed5db0e1ce1c919c3.tar.gz
nextcloud-server-936f34d3a5bb12181608574ed5db0e1ce1c919c3.zip
feat: Reset route if neither the Viewer of the Sidebar is open
When the viewer or the sidebar is opened, we add the fileid to the route. When both of them are closed, we do not remove the fileid from the route. This means that, upon reload, the sidebar will be opened even though it was closed previously. This PR ensure that the fileid is removed from the route when both the Sidebar and the Viewer are closed. Signed-off-by: Louis Chemineau <louis@chmn.me>
-rw-r--r--apps/files/src/components/FilesListVirtual.vue28
1 files changed, 22 insertions, 6 deletions
diff --git a/apps/files/src/components/FilesListVirtual.vue b/apps/files/src/components/FilesListVirtual.vue
index 17a934ca5cf..4f3bdec9fd9 100644
--- a/apps/files/src/components/FilesListVirtual.vue
+++ b/apps/files/src/components/FilesListVirtual.vue
@@ -77,6 +77,7 @@ import type { UserConfig } from '../types'
import { getFileListHeaders, Folder, View, getFileActions, FileType } from '@nextcloud/files'
import { showError } from '@nextcloud/dialogs'
import { translate as t, translatePlural as n } from '@nextcloud/l10n'
+import { subscribe, unsubscribe } from '@nextcloud/event-bus'
import { defineComponent } from 'vue'
import { action as sidebarAction } from '../actions/sidebarAction.ts'
@@ -216,8 +217,12 @@ export default defineComponent({
handler() {
// wait for scrolling and updating the actions to settle
this.$nextTick(() => {
- if (this.fileId && this.openFile) {
- this.handleOpenFile(this.fileId)
+ if (this.fileId) {
+ if (this.openFile) {
+ this.handleOpenFile(this.fileId)
+ } else {
+ this.unselectFile()
+ }
}
})
},
@@ -230,6 +235,8 @@ export default defineComponent({
const mainContent = window.document.querySelector('main.app-content') as HTMLElement
mainContent.addEventListener('dragover', this.onDragOver)
+ subscribe('files:sidebar:closed', this.unselectFile)
+
// If the file list is mounted with a fileId specified
// then we need to open the sidebar initially
if (this.fileId) {
@@ -240,6 +247,8 @@ export default defineComponent({
beforeDestroy() {
const mainContent = window.document.querySelector('main.app-content') as HTMLElement
mainContent.removeEventListener('dragover', this.onDragOver)
+
+ unsubscribe('files:sidebar:closed', this.unselectFile)
},
methods: {
@@ -267,15 +276,22 @@ export default defineComponent({
}
},
+ unselectFile() {
+ // If the Sidebar is closed and if openFile is false, remove the file id from the URL
+ if (!this.openFile && OCA.Files.Sidebar.file === '') {
+ window.OCP.Files.Router.goToRoute(
+ null,
+ { ...this.$route.params, fileid: String(this.currentFolder.fileid ?? '') },
+ this.$route.query,
+ )
+ }
+ },
+
/**
* Handle opening a file (e.g. by ?openfile=true)
* @param fileId File to open
*/
handleOpenFile(fileId: number|null) {
- if (!this.openFile) {
- return
- }
-
if (fileId === null || this.openFileId === fileId) {
return
}