diff --git a/lib/components/FilePicker/FilePicker.vue b/lib/components/FilePicker/FilePicker.vue index 0fb658f1..e013f65a 100644 --- a/lib/components/FilePicker/FilePicker.vue +++ b/lib/components/FilePicker/FilePicker.vue @@ -54,6 +54,7 @@ import FileList from './FileList.vue' import FilePickerBreadcrumbs from './FilePickerBreadcrumbs.vue' import FilePickerNavigation from './FilePickerNavigation.vue' +import { emit as emitOnEventBus } from '@nextcloud/event-bus' import { davRootPath } from '@nextcloud/files' import { NcEmptyContent } from '@nextcloud/vue' import { join } from 'path' @@ -249,15 +250,22 @@ const noFilesDescription = computed(() => { /** * Handle creating new folder (breadcrumb menu) + * This will create the folder using WebDAV, reload the directory content and signal the directory creation to fhe files app + * * @param name The new folder name */ -const onCreateFolder = (name: string) => { - client - .createDirectory(join(davRootPath, currentPath.value, name)) +const onCreateFolder = async (name: string) => { + try { + await client.createDirectory(join(davRootPath, currentPath.value, name)) // reload file list - .then(() => loadFiles()) + await loadFiles() + // emit event bus to force files app to reload that file if needed + emitOnEventBus('files:node:created', files.value.filter((file) => file.basename === name)[0]) + } catch (error) { + console.warn('Could not create new folder', { name, error }) // show error to user - .catch((e) => showError(t('Could not create the new folder'))) + showError(t('Could not create the new folder')) + } } diff --git a/lib/composables/dav.ts b/lib/composables/dav.ts index b1a365e1..43877966 100644 --- a/lib/composables/dav.ts +++ b/lib/composables/dav.ts @@ -35,7 +35,7 @@ import { onMounted, ref, watch } from 'vue' export const useDAVFiles = function( currentView: Ref<'files'|'recent'|'favorites'> | ComputedRef<'files'|'recent'|'favorites'>, currentPath: Ref | ComputedRef, -): { isLoading: Ref, client: WebDAVClient, files: Ref, loadFiles: () => void, getFile: (path: string) => Promise } { +): { isLoading: Ref, client: WebDAVClient, files: Ref, loadFiles: () => Promise, getFile: (path: string) => Promise } { /** * The WebDAV client */ @@ -104,7 +104,7 @@ export const useDAVFiles = function( return { isLoading, files, - loadFiles: () => loadDAVFiles(), + loadFiles: loadDAVFiles, getFile, client, } diff --git a/package-lock.json b/package-lock.json index 321c298e..e104f0b6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,6 +11,7 @@ "dependencies": { "@mdi/svg": "^7.3.67", "@nextcloud/axios": "^2.4.0", + "@nextcloud/event-bus": "^3.1.0", "@nextcloud/files": "^3.0.0-beta.26", "@nextcloud/initial-state": "^2.1.0", "@nextcloud/l10n": "^2.2.0", diff --git a/package.json b/package.json index 9a6193f3..44a7a927 100644 --- a/package.json +++ b/package.json @@ -56,6 +56,7 @@ "dependencies": { "@mdi/svg": "^7.3.67", "@nextcloud/axios": "^2.4.0", + "@nextcloud/event-bus": "^3.1.0", "@nextcloud/files": "^3.0.0-beta.26", "@nextcloud/initial-state": "^2.1.0", "@nextcloud/l10n": "^2.2.0",