Skip to content

Commit 11ff3d0

Browse files
committed
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>
1 parent 2480567 commit 11ff3d0

3 files changed

Lines changed: 28 additions & 4 deletions

File tree

apps/files/src/components/FilesListVirtual.vue

Lines changed: 25 additions & 1 deletion
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,7 +201,7 @@ 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+
if (this.fileId) {
204205
this.handleOpenFile(this.fileId)
205206
}
206207
})
@@ -214,6 +215,8 @@ export default defineComponent({
214215
const mainContent = window.document.querySelector('main.app-content') as HTMLElement
215216
mainContent.addEventListener('dragover', this.onDragOver)
216217
218+
subscribe('files:sidebar:closed', this.handleSideBarCloseEvent)
219+
217220
// If the file list is mounted with a fileId specified
218221
// then we need to open the sidebar initially
219222
if (this.fileId) {
@@ -224,6 +227,8 @@ export default defineComponent({
224227
beforeDestroy() {
225228
const mainContent = window.document.querySelector('main.app-content') as HTMLElement
226229
mainContent.removeEventListener('dragover', this.onDragOver)
230+
231+
unsubscribe('files:sidebar:closed', this.handleSideBarCloseEvent)
227232
},
228233
229234
methods: {
@@ -251,12 +256,31 @@ export default defineComponent({
251256
}
252257
},
253258
259+
handleSideBarCloseEvent() {
260+
if (!this.openFile) {
261+
window.OCP.Files.Router.goToRoute(
262+
null,
263+
{ ...this.$route.params, fileid: undefined },
264+
this.$route.query,
265+
)
266+
}
267+
},
268+
254269
/**
255270
* Handle opening a file (e.g. by ?openfile=true)
256271
* @param fileId File to open
257272
*/
258273
handleOpenFile(fileId: number|null) {
259274
if (!this.openFile) {
275+
// If the Sidebar is closed and if openFile is false, remove the file id from the URL
276+
if (OCA.Files.Sidebar.file === '') {
277+
window.OCP.Files.Router.goToRoute(
278+
null,
279+
{ ...this.$route.params, fileid: undefined },
280+
this.$route.query,
281+
)
282+
}
283+
260284
return
261285
}
262286

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)