Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FilePicker: Signal folder creation to files app #1095

Merged
merged 1 commit into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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