Skip to content

Commit 512bd5a

Browse files
authored
Merge pull request #48002 from nextcloud/backport/47920/stable28
[stable28] feat: Reset route if neither the Viewer of the Sidebar is open
2 parents ef4b1c3 + f5e0c9e commit 512bd5a

3 files changed

Lines changed: 33 additions & 11 deletions

File tree

apps/files/src/components/FilesListVirtual.vue

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ import { getFileListHeaders, Folder, View, getFileActions, FileType } from '@nex
7878
import { showError } from '@nextcloud/dialogs'
7979
import { loadState } from '@nextcloud/initial-state'
8080
import { translate as t, translatePlural as n } from '@nextcloud/l10n'
81+
import { subscribe, unsubscribe } from '@nextcloud/event-bus'
8182
import { defineComponent } from 'vue'
8283
8384
import { action as sidebarAction } from '../actions/sidebarAction.ts'
@@ -210,10 +211,20 @@ export default defineComponent({
210211
this.scrollToFile(fileId, false)
211212
},
212213
213-
openFile(open: boolean) {
214-
if (open) {
215-
this.$nextTick(() => this.handleOpenFile(this.fileId))
216-
}
214+
openFile: {
215+
handler() {
216+
// wait for scrolling and updating the actions to settle
217+
this.$nextTick(() => {
218+
if (this.fileId) {
219+
if (this.openFile) {
220+
this.handleOpenFile(this.fileId)
221+
} else {
222+
this.unselectFile()
223+
}
224+
}
225+
})
226+
},
227+
immediate: true,
217228
},
218229
},
219230
@@ -226,11 +237,15 @@ export default defineComponent({
226237
this.scrollToFile(id ?? this.fileId)
227238
this.openSidebarForFile(id ?? this.fileId)
228239
this.handleOpenFile(id ?? null)
240+
241+
subscribe('files:sidebar:closed', this.unselectFile)
229242
},
230243
231244
beforeDestroy() {
232245
const mainContent = window.document.querySelector('main.app-content') as HTMLElement
233246
mainContent.removeEventListener('dragover', this.onDragOver)
247+
248+
unsubscribe('files:sidebar:closed', this.unselectFile)
234249
},
235250
236251
methods: {
@@ -258,15 +273,22 @@ export default defineComponent({
258273
}
259274
},
260275
276+
unselectFile() {
277+
// If the Sidebar is closed and if openFile is false, remove the file id from the URL
278+
if (!this.openFile && OCA.Files.Sidebar.file === '') {
279+
window.OCP.Files.Router.goToRoute(
280+
null,
281+
{ ...this.$route.params, fileid: String(this.currentFolder.fileid ?? '') },
282+
this.$route.query,
283+
)
284+
}
285+
},
286+
261287
/**
262288
* Handle opening a file (e.g. by ?openfile=true)
263289
* @param fileId File to open
264290
*/
265291
handleOpenFile(fileId: number|null) {
266-
if (!this.openFile) {
267-
return
268-
}
269-
270292
if (fileId === null || this.openFileId === fileId) {
271293
return
272294
}

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)