Skip to content

Commit fc91cf3

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 <[email protected]>
1 parent 2480567 commit fc91cf3

File tree

3 files changed

+28
-4
lines changed

3 files changed

+28
-4
lines changed

apps/files/src/components/FilesListVirtual.vue

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ import VirtualList from './VirtualList.vue'
8383
import logger from '../logger.ts'
8484
import FilesListTableHeaderActions from './FilesListTableHeaderActions.vue'
8585
import FileListFilters from './FileListFilters.vue'
86+
import { subscribe, unsubscribe } from '@nextcloud/event-bus'
8687
8788
export default defineComponent({
8889
name: 'FilesListVirtual',
@@ -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 (OCA.Viewer.file === '') {
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)