]> source.dussan.org Git - nextcloud-server.git/commitdiff
fix(files): router and fileid sidebar open
authorJohn Molakvoæ <skjnldsv@protonmail.com>
Sat, 12 Aug 2023 15:07:46 +0000 (17:07 +0200)
committerJohn Molakvoæ <skjnldsv@protonmail.com>
Thu, 17 Aug 2023 16:56:38 +0000 (18:56 +0200)
Signed-off-by: John Molakvoæ <skjnldsv@protonmail.com>
apps/files/src/actions/openFolderAction.ts
apps/files/src/actions/sidebarAction.ts
apps/files/src/actions/viewInFolderAction.ts
apps/files/src/components/FileEntry.vue
apps/files/src/components/FilesListVirtual.vue
apps/files/src/router/router.ts
apps/files/src/services/RouterService.ts

index 9e8325159766cd1c4937ad23ac5f6817e68145d7..c0e03b20af0a2ea4f96349e7110f1df090160488 100644 (file)
@@ -59,7 +59,7 @@ export const action = new FileAction({
 
                window.OCP.Files.Router.goToRoute(
                        null,
-                       { fileid: undefined },
+                       { view: view.id, fileid: undefined },
                        { dir: join(dir, node.basename), fileid: undefined },
                )
                return null
index 6c553d97902f56ecc9367fc326d8d4e7a4436480..0073d1c8490afe0cd3113b0baa97fa56fee1f8ea 100644 (file)
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  *
  */
+import type { Navigation } from '../services/Navigation'
+
+import { Permission, type Node } from '@nextcloud/files'
 import { translate as t } from '@nextcloud/l10n'
 import InformationSvg from '@mdi/svg/svg/information-variant.svg?raw'
-import { Permission, type Node } from '@nextcloud/files'
 
 import { registerFileAction, FileAction } from '../services/FileAction'
 import logger from '../logger.js'
@@ -48,11 +50,19 @@ export const action = new FileAction({
                return (nodes[0].root?.startsWith('/files/') && nodes[0].permissions !== Permission.NONE) ?? false
        },
 
-       async exec(node: Node) {
+       async exec(node: Node, view: Navigation) {
                try {
                        // TODO: migrate Sidebar to use a Node instead
                        window?.OCA?.Files?.Sidebar?.open?.(node.path)
 
+                       // Silently update current fileid
+                       window.OCP.Files.Router.goToRoute(
+                               null,
+                               { view: view.id, fileid: node.fileid },
+                               { dir: node.dirname },
+                               true,
+                       )
+
                        return null
                } catch (error) {
                        logger.error('Error while opening sidebar', { error })
index 2f603e6cf3a3e7d5632be582422e903b4ef6f8a4..f0c5d2485a3b3c3ca376e38d6ac14440c53a8a6a 100644 (file)
@@ -61,7 +61,7 @@ export const action = new FileAction({
                window.OCP.Files.Router.goToRoute(
                        null,
                        { view: 'files', fileid: node.fileid },
-                       { dir: node.dirname, fileid: node.fileid },
+                       { dir: node.dirname },
                )
                return null
        },
index d189c83e63a7af0e220e3546202d0c689a8d0888..6495a84db30965dd074c8260679cbd1fb55efcd9 100644 (file)
@@ -377,7 +377,7 @@ export default Vue.extend({
                        return this.selectionStore.selected
                },
                isSelected() {
-                       return this.selectedFiles.includes(this.source?.fileid?.toString?.())
+                       return this.selectedFiles.includes(this.fileid)
                },
 
                cropPreviews() {
@@ -481,7 +481,7 @@ export default Vue.extend({
                },
 
                isActive() {
-                       return this.fileid === this.currentFileId
+                       return this.fileid === this.currentFileId?.toString?.()
                },
        },
 
@@ -502,16 +502,6 @@ export default Vue.extend({
                isRenaming() {
                        this.startRenaming()
                },
-
-               /**
-                * Open the sidebar if the file is active
-                */
-               isActive(active) {
-                       const Sidebar = window?.OCA?.Files?.Sidebar
-                       if (active && Sidebar && Sidebar.file !== this.source.path) {
-                               Sidebar.open(this.source.path)
-                       }
-               },
        },
 
        /**
index 18c58a6c41b5f92624117e12f3828c0ef8cd549d..c943b8998973a1f0f4800e40cc1e9d1fdfc72a92 100644 (file)
@@ -68,7 +68,7 @@
 
 <script lang="ts">
 import { translate, translatePlural } from '@nextcloud/l10n'
-import { getFileListHeaders } from '@nextcloud/files'
+import { getFileListHeaders, type Node } from '@nextcloud/files'
 import Vue from 'vue'
 import VirtualList from './VirtualList.vue'
 
@@ -112,6 +112,7 @@ export default Vue.extend({
                return {
                        FileEntry,
                        headers: getFileListHeaders(),
+                       scrollToIndex: 0,
                }
        },
 
@@ -124,17 +125,6 @@ export default Vue.extend({
                        return parseInt(this.$route.params.fileid || this.$route.query.fileid) || null
                },
 
-               scrollToIndex() {
-                       if (!this.fileId) {
-                               return
-                       }
-                       const index = this.nodes.findIndex(node => node.fileid === this.fileId)
-                       if (index === -1) {
-                               showError(this.t('files', 'File not found'))
-                       }
-                       return Math.max(0, index)
-               },
-
                summaryFile() {
                        const count = this.files.length
                        return translatePlural('files', '{count} file', '{count} files', count, { count })
@@ -171,12 +161,24 @@ export default Vue.extend({
        },
 
        mounted() {
-               // Open the sidebar on the file if it's in the url and
-               // we're just loaded the app for the first time.
-               const Sidebar = window?.OCA?.Files?.Sidebar
-               const node = this.nodes.find(node => node.fileid === this.fileId)
-               if (Sidebar && node) {
-                       Sidebar.open(node.path)
+               // Scroll to the file if it's in the url
+               if (this.fileId) {
+                       const index = this.nodes.findIndex(node => node.fileid === this.fileId)
+                       if (index === -1) {
+                               showError(this.t('files', 'File not found'))
+                       }
+                       this.scrollToIndex = Math.max(0, index)
+               }
+
+               // Open the file sidebar if we have the room for it
+               if (document.documentElement.clientWidth > 1024) {
+                       // Open the sidebar on the file if it's in the url and
+                       // we're just loaded the app for the first time.
+                       const Sidebar = window?.OCA?.Files?.Sidebar
+                       const node = this.nodes.find(node => node.fileid === this.fileId) as Node
+                       if (Sidebar && node) {
+                               Sidebar.open(node.path)
+                       }
                }
        },
 
index 6ba8bec92fb32d6f2d95e2d0f1188c56978dcbb6..5e917109162496f2e09623ceffb570ebc2ee9566 100644 (file)
@@ -38,7 +38,7 @@ const router = new Router({
                {
                        path: '/',
                        // Pretending we're using the default view
-                       alias: '/files',
+                       redirect: { name: 'filelist' },
                },
                {
                        path: '/:view/:fileid?',
index 55033f9c79ced035efb310c59595d71f17fa6041..7e3bd854e711720a35da0c4b8748c9f6691e3dd4 100644 (file)
@@ -31,6 +31,18 @@ export default class RouterService {
                this._router = router
        }
 
+       get name(): string | null | undefined {
+               return this._router.currentRoute.name
+       }
+
+       get query(): Dictionary<string | (string | null)[] | null | undefined> {
+               return this._router.currentRoute.query || {}
+       }
+
+       get params(): Dictionary<string> {
+               return this._router.currentRoute.params || {}
+       }
+
        /**
         * Trigger a route change on the files app
         *