From a96681b0b0c4b39f0d4ef704e5dced1e57d52665 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Molakvo=C3=A6?= Date: Thu, 8 Feb 2024 15:08:06 +0100 Subject: [PATCH] fix: support 28 Files MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: John Molakvoæ --- src/components/RecommendedFile.vue | 36 ++++++++++++++---------------- src/main.js | 7 +++--- 2 files changed, 20 insertions(+), 23 deletions(-) diff --git a/src/components/RecommendedFile.vue b/src/components/RecommendedFile.vue index ada40308..450d2b9c 100644 --- a/src/components/RecommendedFile.vue +++ b/src/components/RecommendedFile.vue @@ -96,9 +96,6 @@ export default { return this.name } }, - isFileListAvailable() { - return OCA.Files.App.fileList.changeDirectory && OCA.Files.App.fileList.scrollTo - }, path() { return (this.directory === '/' ? '' : this.directory) + '/' + this.name }, @@ -119,26 +116,27 @@ export default { } }, methods: { - changeDirectory(directory) { - // This call does not always return a promise, so we - // wrap it - return Promise.resolve(OCA.Files.App.fileList.changeDirectory(directory)) - }, - scrollTo(name) { - OCA.Files.App.fileList.scrollTo(name) - }, navigate() { - if (OCA.Viewer && OCA.Viewer.mimetypes.indexOf(this.mimeType) !== -1) { - OCA.Viewer.open({ path: this.path }) + // If Viewer is enabled and supports this file, open directly + if (window.OCA?.Viewer && window.OCA.Viewer.mimetypes.indexOf(this.mimeType) !== -1) { + window.OCA.Viewer.open({ path: this.path }) return } - if (this.isFileListAvailable) { - this.changeDirectory(this.directory) - .then(() => this.scrollTo(this.name)) - .catch(console.error.bind(this)) - } else { - window.location = generateUrl('/f/' + this.id) + + // Navigate to the file if the file router is available + if (window.OCP?.Files?.Router) { + window.OCP.Files.Router.goToRoute( + // use default route + null, + // recommendations is only enabled on files + { view: 'files', fileid: this.id }, + { dir: this.directory }, + ) + return } + + // Fallback to the old way of navigating to the file + window.location = generateUrl('/f/' + this.id) }, }, } diff --git a/src/main.js b/src/main.js index 8900bbb6..4ec3f007 100644 --- a/src/main.js +++ b/src/main.js @@ -45,11 +45,10 @@ const header = new Header({ // Load recommendations store.dispatch('fetchRecommendations') - const vm = new View({ - propsData: {}, + new View({ + name: 'RecommendationsHeader', store, - }) - vm.$mount(el) + }).$mount(el) // Create settings const SettingsView = Vue.extend(Settings)