From 2c3774892ea1e40fa4474ce6b304b4522ebd842b Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Tue, 17 Jun 2025 19:24:41 +0200 Subject: [PATCH] feat(files): add `getDirectoryByPath` to files store Signed-off-by: Ferdinand Thiessen --- apps/files/src/eventbus.d.ts | 8 ++++++-- apps/files/src/store/files.ts | 23 ++++++++++++++++++----- apps/files/src/views/FilesList.vue | 11 +---------- 3 files changed, 25 insertions(+), 17 deletions(-) diff --git a/apps/files/src/eventbus.d.ts b/apps/files/src/eventbus.d.ts index fb61b4a6d03..c9f0fbf86e5 100644 --- a/apps/files/src/eventbus.d.ts +++ b/apps/files/src/eventbus.d.ts @@ -2,7 +2,9 @@ * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors * SPDX-License-Identifier: AGPL-3.0-or-later */ + import type { IFileListFilter, Node } from '@nextcloud/files' +import type { SearchScope } from './types' declare module '@nextcloud/event-bus' { export interface NextcloudEvents { @@ -13,6 +15,9 @@ declare module '@nextcloud/event-bus' { 'files:favorites:removed': Node 'files:favorites:added': Node + 'files:filter:added': IFileListFilter + 'files:filter:removed': string + // the state of some filters has changed 'files:filters:changed': undefined 'files:node:created': Node @@ -22,8 +27,7 @@ declare module '@nextcloud/event-bus' { 'files:node:renamed': Node 'files:node:moved': { node: Node, oldSource: string } - 'files:filter:added': IFileListFilter - 'files:filter:removed': string + 'files:search:updated': { query: string, scope: SearchScope } } } diff --git a/apps/files/src/store/files.ts b/apps/files/src/store/files.ts index 295704c880b..3591832d0c4 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)) diff --git a/apps/files/src/views/FilesList.vue b/apps/files/src/views/FilesList.vue index 60791a2b527..c50f6bb31b6 100644 --- a/apps/files/src/views/FilesList.vue +++ b/apps/files/src/views/FilesList.vue @@ -325,16 +325,7 @@ export default defineComponent({ return } - if (this.directory === '/') { - return this.filesStore.getRoot(this.currentView.id) - } - - const source = this.pathsStore.getPath(this.currentView.id, this.directory) - if (source === undefined) { - return - } - - return this.filesStore.getNode(source) as Folder + return this.filesStore.getDirectoryByPath(this.currentView.id, this.directory) }, dirContents(): Node[] {