diff options
Diffstat (limited to 'apps/files/src/store/files.ts')
-rw-r--r-- | apps/files/src/store/files.ts | 29 |
1 files changed, 21 insertions, 8 deletions
diff --git a/apps/files/src/store/files.ts b/apps/files/src/store/files.ts index a2413b5a1ba..0bcf4ce9350 100644 --- a/apps/files/src/store/files.ts +++ b/apps/files/src/store/files.ts @@ -54,13 +54,13 @@ export const useFilesStore = function(...args) { actions: { /** - * Get cached child nodes within a given path + * Get cached directory matching a given path * - * @param service The service (files view) - * @param path The path relative within the service - * @return Array of cached nodes within the path + * @param service - The service (files view) + * @param path - The path relative within the service + * @return The folder if found */ - getNodesByPath(service: string, path?: string): Node[] { + getDirectoryByPath(service: string, path?: string): Folder | undefined { const pathsStore = usePathsStore() let folder: Folder | undefined @@ -74,6 +74,19 @@ export const useFilesStore = function(...args) { } } + return folder + }, + + /** + * Get cached child nodes within a given path + * + * @param service - The service (files view) + * @param path - The path relative within the service + * @return Array of cached nodes within the path + */ + getNodesByPath(service: string, path?: string): Node[] { + const folder = this.getDirectoryByPath(service, path) + // If we found a cache entry and the cache entry was already loaded (has children) then use it return (folder?._children ?? []) .map((source: string) => this.getNode(source)) @@ -135,19 +148,19 @@ export const useFilesStore = function(...args) { // If we have multiple nodes with the same file ID, we need to update all of them const nodes = this.getNodesById(node.fileid) if (nodes.length > 1) { - await Promise.all(nodes.map(fetchNode)).then(this.updateNodes) + await Promise.all(nodes.map(node => fetchNode(node.path))).then(this.updateNodes) logger.debug(nodes.length + ' nodes updated in store', { fileid: node.fileid }) return } // If we have only one node with the file ID, we can update it directly - if (node.source === nodes[0].source) { + if (nodes.length === 1 && node.source === nodes[0].source) { this.updateNodes([node]) return } // Otherwise, it means we receive an event for a node that is not in the store - fetchNode(node).then(n => this.updateNodes([n])) + fetchNode(node.path).then(n => this.updateNodes([n])) }, // Handlers for legacy sidebar (no real nodes support) |