aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files/src
diff options
context:
space:
mode:
authorFerdinand Thiessen <opensource@fthiessen.de>2024-08-08 13:51:33 +0200
committerFerdinand Thiessen <opensource@fthiessen.de>2024-08-08 13:51:33 +0200
commitdab678f7c502acc126b9956529deb21223546a9c (patch)
tree0fb2be0d43432df71508b0002286fc7789045158 /apps/files/src
parent2777cf90e333bf57491784812148c6b3db437c85 (diff)
downloadnextcloud-server-fix/make-router-reactive.tar.gz
nextcloud-server-fix/make-router-reactive.zip
[WIP] Make router interface reactive while being framework agnosticfix/make-router-reactive
Currently it is only reactive when used within the files app, because the files app can access the vue router directly, problem is when other apps use it, then it is not reactive anymore as they have a different Vue. Also if you do not use Vue but vanilla JS or something else, the router params and query would not be reactive. Problem that this is solving: React to route changes only, watching current view and query will trigger on different time frames causing invalid states. e.g. changing the view from A to B and the query from `/foo` to `/` will cause: 1. View change 2. query change But after 1 the query is invalid and cause issues. So this changes will allow listening the route change which is combined 1 & 2 -> valid state. Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
Diffstat (limited to 'apps/files/src')
-rw-r--r--apps/files/src/components/FilesListVirtual.vue20
-rw-r--r--apps/files/src/services/RouterService.ts37
-rw-r--r--apps/files/src/views/FilesList.vue4
3 files changed, 54 insertions, 7 deletions
diff --git a/apps/files/src/components/FilesListVirtual.vue b/apps/files/src/components/FilesListVirtual.vue
index 9a35e9ff855..782e2bd3587 100644
--- a/apps/files/src/components/FilesListVirtual.vue
+++ b/apps/files/src/components/FilesListVirtual.vue
@@ -4,7 +4,7 @@
-->
<template>
<VirtualList ref="table"
- :data-component="userConfig.grid_view ? FileEntryGrid : FileEntry"
+ :data-component="fileEntryComponent"
:data-key="'source'"
:data-sources="nodes"
:grid-mode="userConfig.grid_view"
@@ -132,8 +132,6 @@ export default defineComponent({
data() {
return {
- FileEntry,
- FileEntryGrid,
headers: getFileListHeaders(),
scrollToIndex: 0,
openFileId: null as number|null,
@@ -141,6 +139,13 @@ export default defineComponent({
},
computed: {
+ /**
+ * The Vue component to use for file list entries
+ */
+ fileEntryComponent() {
+ return this.userConfig.grid_view ? FileEntryGrid : FileEntry
+ },
+
userConfig(): UserConfig {
return this.userConfigStore.userConfig
},
@@ -218,6 +223,11 @@ export default defineComponent({
},
methods: {
+ reset() {
+ this.scrollToIndex = 0
+ this.openFileId = null
+ },
+
// Open the file sidebar if we have the room for it
// but don't open the sidebar for the current folder
openSidebarForFile(fileId) {
@@ -236,6 +246,10 @@ export default defineComponent({
if (fileId) {
const index = this.nodes.findIndex(node => node.fileid === fileId)
if (warn && index === -1 && fileId !== this.currentFolder.fileid) {
+ logger.error('File to scroll to not found', {
+ folder: this.currentFolder,
+ fileId,
+ })
showError(this.t('files', 'File not found'))
}
this.scrollToIndex = Math.max(0, index)
diff --git a/apps/files/src/services/RouterService.ts b/apps/files/src/services/RouterService.ts
index 84516465495..65113eb32d7 100644
--- a/apps/files/src/services/RouterService.ts
+++ b/apps/files/src/services/RouterService.ts
@@ -4,14 +4,47 @@
*/
import type { Route } from 'vue-router'
import type VueRouter from 'vue-router'
-import type { Dictionary, Location } from 'vue-router/types/router'
+import type { Dictionary, Location } from 'vue-router/types/router.d.ts'
+import { TypedEventTarget } from 'typescript-event-target'
-export default class RouterService {
+interface NavigationEventData {
+ name: Route['name']
+ params: Route['params']
+ query: Route['query']
+}
+
+class NavigationEvent extends CustomEvent<NavigationEventData> {
+
+ constructor({ name, params, query }: Route) {
+ super('navigation', {
+ detail: {
+ name,
+ // Do not let API users mess with internal state of our VueRouter (e.g. if they use Vue it could conflict)
+ params: structuredClone(params),
+ query: structuredClone(query),
+ },
+ })
+ }
+
+}
+
+interface RouterEventMap {
+ navigation: NavigationEvent
+}
+
+export default class RouterService extends TypedEventTarget<RouterEventMap> {
private _router: VueRouter
constructor(router: VueRouter) {
+ super()
this._router = router
+ this._router.beforeEach((to, from, next) => {
+ // emit event
+ this.dispatchTypedEvent('navigation', new NavigationEvent(to))
+ // continue
+ next()
+ })
}
get name(): string | null | undefined {
diff --git a/apps/files/src/views/FilesList.vue b/apps/files/src/views/FilesList.vue
index a127fd4c35c..bca95d0d25a 100644
--- a/apps/files/src/views/FilesList.vue
+++ b/apps/files/src/views/FilesList.vue
@@ -397,7 +397,7 @@ export default defineComponent({
showCustomEmptyView() {
return !this.loading && this.isEmptyDir && this.currentView?.emptyView !== undefined
- }
+ },
},
watch: {
@@ -657,7 +657,7 @@ export default defineComponent({
filterDirContent() {
let nodes = this.dirContents
for (const filter of this.filtersStore.sortedFilters) {
- nodes = filter.filter(nodes)
+ nodes = filter.filter(nodes) as Node[]
}
this.dirContentsFiltered = nodes
},