Skip to content

Commit

Permalink
feat: Reset route if neither the Viewer of the Sidebar is open
Browse files Browse the repository at this point in the history
Signed-off-by: Louis Chemineau <louis@chmn.me>
  • Loading branch information
artonge committed Sep 12, 2024
1 parent 5fc5148 commit 0bc7e5e
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion apps/files/src/components/FilesListVirtual.vue
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ import VirtualList from './VirtualList.vue'
import logger from '../logger.ts'
import FilesListTableHeaderActions from './FilesListTableHeaderActions.vue'
import FileListFilters from './FileListFilters.vue'
import { subscribe, unsubscribe } from '@nextcloud/event-bus'

export default defineComponent({
name: 'FilesListVirtual',
Expand Down Expand Up @@ -200,7 +201,7 @@ export default defineComponent({
handler() {
// wait for scrolling and updating the actions to settle
this.$nextTick(() => {
if (this.fileId && this.openFile) {
if (this.fileId) {
this.handleOpenFile(this.fileId)
}
})
Expand All @@ -214,6 +215,8 @@ export default defineComponent({
const mainContent = window.document.querySelector('main.app-content') as HTMLElement
mainContent.addEventListener('dragover', this.onDragOver)

subscribe('files:sidebar:closed', this.handleSideBarCloseEvent)

// If the file list is mounted with a fileId specified
// then we need to open the sidebar initially
if (this.fileId) {
Expand All @@ -224,6 +227,8 @@ export default defineComponent({
beforeDestroy() {
const mainContent = window.document.querySelector('main.app-content') as HTMLElement
mainContent.removeEventListener('dragover', this.onDragOver)

unsubscribe('files:sidebar:closed', this.handleSideBarCloseEvent)
},

methods: {
Expand Down Expand Up @@ -251,12 +256,31 @@ export default defineComponent({
}
},

handleSideBarCloseEvent() {
if (OCA.Viewer.file === '') {
window.OCP.Files.Router.goToRoute(
null,
{ ...this.$route.params, fileid: undefined },
{ ...this.$route.query },
)
}
},

/**
* Handle opening a file (e.g. by ?openfile=true)
* @param fileId File to open
*/
handleOpenFile(fileId: number|null) {
if (!this.openFile) {
// If the Sidebar is closed and if openFile is false, remove the file id from the URL
if (OCA.Files.Sidebar.file === '') {
window.OCP.Files.Router.goToRoute(
null,
{ ...this.$route.params, fileid: undefined },
{ ...this.$route.query },
)
}

return
}

Expand Down

0 comments on commit 0bc7e5e

Please sign in to comment.