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:55:55 +0200
commit55a5f2a46fef2037e9e56d2cf52714dd41914496 (patch)
tree25b0453c806d619d7cc00e196797b51b859984c2
parentef4b1c38b9b8288fe397e441fc98d4df1952237c (diff)
downloadnextcloud-server-55a5f2a46fef2037e9e56d2cf52714dd41914496.tar.gz
nextcloud-server-55a5f2a46fef2037e9e56d2cf52714dd41914496.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.vue38
1 files changed, 30 insertions, 8 deletions
diff --git a/apps/files/src/components/FilesListVirtual.vue b/apps/files/src/components/FilesListVirtual.vue
index 65c88df2184..af8696c6e2b 100644
--- a/apps/files/src/components/FilesListVirtual.vue
+++ b/apps/files/src/components/FilesListVirtual.vue
@@ -78,6 +78,7 @@ import { getFileListHeaders, Folder, View, getFileActions, FileType } from '@nex
import { showError } from '@nextcloud/dialogs'
import { loadState } from '@nextcloud/initial-state'
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'
@@ -210,10 +211,20 @@ export default defineComponent({
this.scrollToFile(fileId, false)
},
- openFile(open: boolean) {
- if (open) {
- this.$nextTick(() => this.handleOpenFile(this.fileId))
- }
+ openFile: {
+ handler() {
+ // wait for scrolling and updating the actions to settle
+ this.$nextTick(() => {
+ if (this.fileId) {
+ if (this.openFile) {
+ this.handleOpenFile(this.fileId)
+ } else {
+ this.unselectFile()
+ }
+ }
+ })
+ },
+ immediate: true,
},
},
@@ -226,11 +237,15 @@ export default defineComponent({
this.scrollToFile(id ?? this.fileId)
this.openSidebarForFile(id ?? this.fileId)
this.handleOpenFile(id ?? null)
+
+ subscribe('files:sidebar:closed', this.unselectFile)
},
beforeDestroy() {
const mainContent = window.document.querySelector('main.app-content') as HTMLElement
mainContent.removeEventListener('dragover', this.onDragOver)
+
+ unsubscribe('files:sidebar:closed', this.unselectFile)
},
methods: {
@@ -258,15 +273,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
}