Skip to content

Commit 3c9111e

Browse files
authored
Merge pull request #47920 from nextcloud/artonge/feat/reset_route_when_sidebar_and_viewer_are_close
feat: Reset route if neither the Viewer of the Sidebar is open
2 parents 6a6910f + 2da1c57 commit 3c9111e

3 files changed

Lines changed: 26 additions & 10 deletions

File tree

apps/files/src/components/FilesListVirtual.vue

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ import type { UserConfig } from '../types'
6565
import { getFileListHeaders, Folder, View, getFileActions, FileType } from '@nextcloud/files'
6666
import { showError } from '@nextcloud/dialogs'
6767
import { translate as t } from '@nextcloud/l10n'
68+
import { subscribe, unsubscribe } from '@nextcloud/event-bus'
6869
import { defineComponent } from 'vue'
6970
7071
import { action as sidebarAction } from '../actions/sidebarAction.ts'
@@ -200,8 +201,12 @@ export default defineComponent({
200201
handler() {
201202
// wait for scrolling and updating the actions to settle
202203
this.$nextTick(() => {
203-
if (this.fileId && this.openFile) {
204-
this.handleOpenFile(this.fileId)
204+
if (this.fileId) {
205+
if (this.openFile) {
206+
this.handleOpenFile(this.fileId)
207+
} else {
208+
this.unselectFile()
209+
}
205210
}
206211
})
207212
},
@@ -214,6 +219,8 @@ export default defineComponent({
214219
const mainContent = window.document.querySelector('main.app-content') as HTMLElement
215220
mainContent.addEventListener('dragover', this.onDragOver)
216221
222+
subscribe('files:sidebar:closed', this.unselectFile)
223+
217224
// If the file list is mounted with a fileId specified
218225
// then we need to open the sidebar initially
219226
if (this.fileId) {
@@ -224,6 +231,8 @@ export default defineComponent({
224231
beforeDestroy() {
225232
const mainContent = window.document.querySelector('main.app-content') as HTMLElement
226233
mainContent.removeEventListener('dragover', this.onDragOver)
234+
235+
unsubscribe('files:sidebar:closed', this.unselectFile)
227236
},
228237
229238
methods: {
@@ -251,15 +260,22 @@ export default defineComponent({
251260
}
252261
},
253262
263+
unselectFile() {
264+
// If the Sidebar is closed and if openFile is false, remove the file id from the URL
265+
if (!this.openFile && OCA.Files.Sidebar.file === '') {
266+
window.OCP.Files.Router.goToRoute(
267+
null,
268+
{ ...this.$route.params, fileid: String(this.currentFolder.fileid ?? '') },
269+
this.$route.query,
270+
)
271+
}
272+
},
273+
254274
/**
255275
* Handle opening a file (e.g. by ?openfile=true)
256276
* @param fileId File to open
257277
*/
258278
handleOpenFile(fileId: number|null) {
259-
if (!this.openFile) {
260-
return
261-
}
262-
263279
if (fileId === null || this.openFileId === fileId) {
264280
return
265281
}
@@ -282,7 +298,7 @@ export default defineComponent({
282298
.at(0)
283299
// Some file types do not have a default action (e.g. they can only be downloaded)
284300
// So if there is an enabled default action, so execute it
285-
defaultAction?.exec(node, this.currentView, this.currentFolder.path)
301+
defaultAction?.exec(node, this.currentView, this.currentFolderpath)
286302
},
287303
288304
onDragOver(event: DragEvent) {

dist/files-main.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/files-main.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)