Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable30] feat: Reset route if neither the Viewer of the Sidebar is open #48000

Merged
merged 2 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 22 additions & 6 deletions apps/files/src/components/FilesListVirtual.vue
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ import type { UserConfig } from '../types'
import { getFileListHeaders, Folder, View, getFileActions, FileType } from '@nextcloud/files'
import { showError } from '@nextcloud/dialogs'
import { translate as t } from '@nextcloud/l10n'
import { subscribe, unsubscribe } from '@nextcloud/event-bus'
import { defineComponent } from 'vue'

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

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

// 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 +231,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.unselectFile)
},

methods: {
Expand Down Expand Up @@ -251,15 +260,22 @@ export default defineComponent({
}
},

unselectFile() {
// If the Sidebar is closed and if openFile is false, remove the file id from the URL
if (!this.openFile && OCA.Files.Sidebar.file === '') {
window.OCP.Files.Router.goToRoute(
null,
{ ...this.$route.params, fileid: String(this.currentFolder.fileid ?? '') },
this.$route.query,
)
}
},

/**
* Handle opening a file (e.g. by ?openfile=true)
* @param fileId File to open
*/
handleOpenFile(fileId: number|null) {
if (!this.openFile) {
return
}

if (fileId === null || this.openFileId === fileId) {
return
}
Expand Down
4 changes: 2 additions & 2 deletions dist/files-main.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/files-main.js.map

Large diffs are not rendered by default.

Loading