aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files/src/store/paths.ts
diff options
context:
space:
mode:
Diffstat (limited to 'apps/files/src/store/paths.ts')
-rw-r--r--apps/files/src/store/paths.ts54
1 files changed, 47 insertions, 7 deletions
diff --git a/apps/files/src/store/paths.ts b/apps/files/src/store/paths.ts
index d678b5bc592..49b0ec9495b 100644
--- a/apps/files/src/store/paths.ts
+++ b/apps/files/src/store/paths.ts
@@ -21,12 +21,16 @@
*/
import type { FileId, PathsStore, PathOptions, ServicesState } from '../types'
import { defineStore } from 'pinia'
-import { Node, getNavigation } from '@nextcloud/files'
+import { FileType, Folder, Node, getNavigation } from '@nextcloud/files'
import { subscribe } from '@nextcloud/event-bus'
import Vue from 'vue'
import logger from '../logger'
+import { useFilesStore } from './files'
+
export const usePathsStore = function(...args) {
+ const files = useFilesStore()
+
const store = defineStore('paths', {
state: () => ({
paths: {} as ServicesState,
@@ -55,16 +59,52 @@ export const usePathsStore = function(...args) {
},
onCreatedNode(node: Node) {
- const currentView = getNavigation().active
+ const service = getNavigation()?.active?.id || 'files'
if (!node.fileid) {
logger.error('Node has no fileid', { node })
return
}
- this.addPath({
- service: currentView?.id || 'files',
- path: node.path,
- fileid: node.fileid,
- })
+
+ // Only add path if it's a folder
+ if (node.type === FileType.Folder) {
+ this.addPath({
+ service,
+ path: node.path,
+ fileid: node.fileid,
+ })
+ }
+
+ // Update parent folder children if exists
+ // If the folder is the root, get it and update it
+ if (node.dirname === '/') {
+ const root = files.getRoot(service)
+ if (!root._children) {
+ Vue.set(root, '_children', [])
+ }
+ root._children.push(node.fileid)
+ return
+ }
+
+ // If the folder doesn't exists yet, it will be
+ // fetched later and its children updated anyway.
+ if (this.paths[service][node.dirname]) {
+ const parentId = this.paths[service][node.dirname]
+ const parentFolder = files.getNode(parentId) as Folder
+ logger.debug('Path already exists, updating children', { parentFolder, node })
+
+ if (!parentFolder) {
+ logger.error('Parent folder not found', { parentId })
+ return
+ }
+
+ if (!parentFolder._children) {
+ Vue.set(parentFolder, '_children', [])
+ }
+ parentFolder._children.push(node.fileid)
+ return
+ }
+
+ logger.debug('Parent path does not exists, skipping children update', { node })
},
},
})