@samitouri / QOSami-HFS / commits / 5ead651f

fix: an alertDialog with the same message of the one just closed won't show

Massimo Melina committed Dec 6, 2025 at 18:07 UTC 5ead651ff7ad79ca2685ce7a6c0b7435b47a5215
1 file changed +19 -16
frontend/src/dialog.ts
+19 -16
@@ -118,33 +118,36 @@ export async function formDialog({ ...rest }: DialogOptions): Promise<any> {
118
119 export type AlertType = 'error' | 'warning' | 'info'
120
121 -let lastMsg: any
121 +let msgShowing: any
122 export function alertDialog(msg: ReactElement | string | Error, type:AlertType='info', title='') {
123 - if (msg === lastMsg) return
124 - lastMsg = msg
123 + if (msg === msgShowing) return // no sense in having 2 on the screen. While not strictly our responsibility, it can be handy off-loader for the caller
124 + const was = msgShowing
125 + msgShowing = msg
126 if (msg instanceof Error)
127 type = 'error'
128 const ret = pendingPromise()
129 + ret.finally(() => {
130 + if (msg === msgShowing) // check, in the unlikely case the order of open/close of alertDialog is not strictly a "stack"
131 + msgShowing = was
132 + })
133 return Object.assign(ret, newDialog({
134 className: 'dialog-alert dialog-alert-'+type,
135 title: title || t(_.capitalize(type)),
136 icon: '!',
137 onClose: ret.resolve,
138 dialogProps: { role: 'alertdialog' },
134 - Content
135 - }))
136 -
137 - function Content(){
138 - if (msg instanceof Error) {
139 - const main = err2msg(msg)
140 - const sub = msg.message
141 - msg = h('div', {}, main,
142 - sub !== main && h('div', { style: { marginTop: 20, fontSize: 'small' } }, sub))
139 + Content() {
140 + if (msg instanceof Error) { // msg is transformed only once to be a ReactElement
141 + const main = err2msg(msg)
142 + const sub = msg.message
143 + msg = h('div', {}, main,
144 + sub !== main && h('div', { style: { marginTop: 20, fontSize: 'small' } }, sub))
145 + }
146 + if (typeof msg === 'string')
147 + msg = h('p', {}, msg)
148 + return msg
149 }
144 - if (typeof msg === 'string')
145 - msg = h('p', {}, msg)
146 - return msg
147 - }
150 + }))
151 }
152
153 export interface ConfirmOptions extends Partial<DialogOptions> {