feat(files): add `getDirectoryByPath` to files store

Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
pull/53662/head
Ferdinand Thiessen 2025-06-17 19:24:41 +07:00
parent 28b2710ef0
commit 2c3774892e
No known key found for this signature in database
GPG Key ID: 45FAE7268762B400
3 changed files with 25 additions and 17 deletions

@ -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 }
}
}

@ -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))

@ -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[] {