@@ -78,6 +78,7 @@ import { getFileListHeaders, Folder, View, getFileActions, FileType } from '@nex
7878import { showError } from ' @nextcloud/dialogs'
7979import { loadState } from ' @nextcloud/initial-state'
8080import { translate as t , translatePlural as n } from ' @nextcloud/l10n'
81+ import { subscribe , unsubscribe } from ' @nextcloud/event-bus'
8182import { defineComponent } from ' vue'
8283
8384import { 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 }
0 commit comments