Skip to content

Commit

Permalink
Merge pull request #1095 from nextcloud-libraries/fix/emit-signal
Browse files Browse the repository at this point in the history
FilePicker: Signal folder creation to files app
  • Loading branch information
susnux authored Nov 1, 2023
2 parents d6bc2b1 + 536be9f commit c1596fe
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
18 changes: 13 additions & 5 deletions lib/components/FilePicker/FilePicker.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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'))
}
}
</script>

Expand Down
4 changes: 2 additions & 2 deletions lib/composables/dav.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> | ComputedRef<string>,
): { isLoading: Ref<boolean>, client: WebDAVClient, files: Ref<Node[]>, loadFiles: () => void, getFile: (path: string) => Promise<Node> } {
): { isLoading: Ref<boolean>, client: WebDAVClient, files: Ref<Node[]>, loadFiles: () => Promise<void>, getFile: (path: string) => Promise<Node> } {
/**
* The WebDAV client
*/
Expand Down Expand Up @@ -104,7 +104,7 @@ export const useDAVFiles = function(
return {
isLoading,
files,
loadFiles: () => loadDAVFiles(),
loadFiles: loadDAVFiles,
getFile,
client,
}
Expand Down
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit c1596fe

Please sign in to comment.