Skip to content

Commit

Permalink
Merge pull request #1207 from nextcloud-libraries/fix/emite-on-close
Browse files Browse the repository at this point in the history
  • Loading branch information
skjnldsv authored Jan 26, 2024
2 parents ece7def + ac80699 commit ed4aa01
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions lib/components/FilePicker/FilePicker.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<NcDialog v-bind="dialogProps" @update:open="handleClose">
<NcDialog v-bind="dialogProps" :open.sync="isOpen" @update:open="handleClose">
<template #navigation="{ isCollapsed }">
<FilePickerNavigation :is-collapsed="isCollapsed" :current-view.sync="currentView" :filter-string.sync="filterString" />
</template>
Expand Down Expand Up @@ -120,6 +120,8 @@ const emit = defineEmits<{
(e: 'close', v?: Node[]): void
}>()
const isOpen = ref(true)
/**
* Props to be passed to the underlying Dialog component
*/
Expand All @@ -143,14 +145,28 @@ const dialogButtons = computed(() => {
return buttons.map((button) => ({
...button,
callback: async () => {
const nodes = selectedFiles.value.length === 0 && props.allowPickDirectory ? [await getFile(currentPath.value)] : selectedFiles.value as Node[]
button.callback(nodes)
emit('close', nodes)
callback: () => {
// lock default close handling
isHandlingCallback = true
handleButtonClick(button.callback)
},
} as IFilePickerButton))
})
/**
* Flag that is set when a button was clicked to prevent the default close event to be emitted
* This is needed as `handleButtonClick` is async and thus might execute after NcDialog already closed
*/
let isHandlingCallback = false
const handleButtonClick = async (callback: IFilePickerButton['callback']) => {
const nodes = selectedFiles.value.length === 0 && props.allowPickDirectory ? [await getFile(currentPath.value)] : selectedFiles.value as Node[]
callback(nodes)
emit('close', nodes)
// Unlock close
isHandlingCallback = false
}
/**
* Name of the currently active view
*/
Expand Down Expand Up @@ -272,7 +288,7 @@ const onCreateFolder = async (name: string) => {
* @param open If the dialog is open
*/
const handleClose = (open: boolean) => {
if (!open) {
if (!open && !isHandlingCallback) {
emit('close')
}
}
Expand Down

0 comments on commit ed4aa01

Please sign in to comment.