Skip to content

Commit f60c73a

Browse files
committed
chore!: drop Dialog.hide method
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
1 parent 3e9e11f commit f60c73a

2 files changed

Lines changed: 31 additions & 40 deletions

File tree

lib/components/GenericDialog.vue

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
-->
55
<template>
66
<NcDialog dialog-classes="nc-generic-dialog"
7-
:buttons
7+
:buttons="dialogButtons"
88
:name
99
:message="text"
10-
@update:open="$emit('close')">
10+
@update:open="$emit('close', false)">
1111
<NcNoteCard v-if="severity" :type="severity">
1212
<p v-text="text" />
1313
</NcNoteCard>
@@ -19,7 +19,7 @@
1919
<script setup lang="ts">
2020
import type { IDialogButton, IDialogSeverity } from './types.ts'
2121
22-
import { onMounted, onUnmounted } from 'vue'
22+
import { computed, onMounted, onUnmounted } from 'vue'
2323
import NcDialog from '@nextcloud/vue/components/NcDialog'
2424
import NcNoteCard from '@nextcloud/vue/components/NcNoteCard'
2525
@@ -51,10 +51,18 @@ const props = defineProps<{
5151
severity?: IDialogSeverity
5252
}>()
5353
54-
defineEmits<{
55-
close: []
54+
const emit = defineEmits<{
55+
close: [buttonClick: boolean]
5656
}>()
5757
58+
const dialogButtons = computed(() => props.buttons?.map((button) => ({
59+
...button,
60+
callback() {
61+
button.callback()
62+
emit('close', true)
63+
},
64+
})))
65+
5866
/**
5967
* Handler used to ensure the message is also shown when the page is unloaded
6068
* This is for backwards compatibility with OC.dialogs

lib/dialogs.ts

Lines changed: 18 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,12 @@
33
* SPDX-License-Identifier: AGPL-3.0-or-later
44
*/
55

6-
import type { IDialogButton } from './components/types'
7-
import type Vue from 'vue'
8-
6+
import type { IDialogButton, IDialogSeverity } from './components/types.ts'
97
import { spawnDialog } from '@nextcloud/vue/functions/dialog'
108

11-
import { DialogSeverity } from './components/types'
129
import GenericDialog from './components/GenericDialog.vue'
1310

14-
export { DialogSeverity } from './components/types'
11+
export type * from './components/types.ts'
1512

1613
/**
1714
* This class provides generic Nextcloud themed dialogs
@@ -21,8 +18,7 @@ export class Dialog {
2118
#name: string
2219
#text: string
2320
#buttons: IDialogButton[]
24-
#severity?: DialogSeverity
25-
#dialog?: Vue
21+
#severity?: IDialogSeverity
2622

2723
/** @deprecated */
2824
#html?: string
@@ -31,13 +27,12 @@ export class Dialog {
3127
name: string,
3228
text: string,
3329
buttons: IDialogButton[] = [],
34-
severity?: DialogSeverity,
30+
severity?: IDialogSeverity,
3531
) {
3632
this.#name = name
3733
this.#text = text
3834
this.#buttons = buttons
3935
this.#severity = severity
40-
this.#dialog = undefined
4136
this.#html = undefined
4237
}
4338

@@ -52,34 +47,22 @@ export class Dialog {
5247

5348
/**
5449
* Spawn and show the dialog - if already open the previous instance will be destroyed
50+
*
5551
* @return Promise that resolves when the dialog is answered successfully and rejects on close
5652
*/
5753
async show() {
58-
if (this.#dialog) {
59-
this.#dialog.$destroy()
54+
const result = await spawnDialog(GenericDialog,
55+
{
56+
buttons: this.#buttons,
57+
name: this.#name,
58+
text: this.#text,
59+
severity: this.#severity,
60+
html: this.#html,
61+
},
62+
)
63+
if (!result) {
64+
throw new Error('Dialog closed')
6065
}
61-
62-
return new Promise((resolve) => {
63-
this.#dialog = spawnDialog(GenericDialog,
64-
{
65-
buttons: this.#buttons,
66-
name: this.#name,
67-
text: this.#text,
68-
severity: this.#severity,
69-
html: this.#html,
70-
},
71-
resolve,
72-
)
73-
})
74-
}
75-
76-
/**
77-
* Hide and destroy the current dialog instance
78-
*
79-
* @deprecated use the promise of the `show` methods for the user interaction.
80-
*/
81-
hide() {
82-
this.#dialog?.$destroy()
8366
}
8467

8568
}
@@ -103,7 +86,7 @@ export class Dialog {
10386
*/
10487
export class DialogBuilder {
10588

106-
#severity?: DialogSeverity
89+
#severity?: IDialogSeverity
10790
#text: string
10891
#name: string
10992
#buttons: IDialogButton[]
@@ -137,7 +120,7 @@ export class DialogBuilder {
137120
* Set the severity of the dialog
138121
* @param severity Severity of the dialog
139122
*/
140-
setSeverity(severity: DialogSeverity) {
123+
setSeverity(severity: IDialogSeverity) {
141124
this.#severity = severity
142125
return this
143126
}

0 commit comments

Comments
 (0)