@@ -65,6 +65,7 @@ import type { UserConfig } from '../types'
6565import { getFileListHeaders , Folder , View , getFileActions , FileType } from ' @nextcloud/files'
6666import { showError } from ' @nextcloud/dialogs'
6767import { translate as t } from ' @nextcloud/l10n'
68+ import { subscribe , unsubscribe } from ' @nextcloud/event-bus'
6869import { defineComponent } from ' vue'
6970
7071import { 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 ) {
0 commit comments