Modal: remove support for onFinished callback (#29852)
* Fix up type for `finished` result of Modal The `finished` promise can be called with an empty array, for example if the dialog is closed by a background click. This was not correctly represented in the typing. Fix that, and add some documentation while we're at it. * Type fixes to onFinished callbacks from Modal These can all be called with zero arguments, despite what the type annotations may say, so mark them accordingly. * Remove uses of Modal `onFinished` property ... because it is confusing. Instead, use the `finished` promise returned by `createDialog`. * Modal: remove support for now-unused `onFinished` prop * StopGapWidgetDriver: use `await` instead of promise chaining * Fix up unit tests
This commit is contained in:
committed by
GitHub
parent
ce1055f5fe
commit
f25fbdebc7
@@ -58,37 +58,32 @@ export function createRedactEventDialog({
|
||||
const roomId = mxEvent.getRoomId();
|
||||
|
||||
if (!roomId) throw new Error(`cannot redact event ${mxEvent.getId()} without room ID`);
|
||||
Modal.createDialog(
|
||||
ConfirmRedactDialog,
|
||||
{
|
||||
event: mxEvent,
|
||||
onFinished: async (proceed, reason): Promise<void> => {
|
||||
if (!proceed) return;
|
||||
const { finished } = Modal.createDialog(ConfirmRedactDialog, { event: mxEvent }, "mx_Dialog_confirmredact");
|
||||
|
||||
const cli = MatrixClientPeg.safeGet();
|
||||
const withRelTypes: Pick<IRedactOpts, "with_rel_types"> = {};
|
||||
finished.then(async ([proceed, reason]) => {
|
||||
if (!proceed) return;
|
||||
|
||||
try {
|
||||
onCloseDialog?.();
|
||||
await cli.redactEvent(roomId, eventId, undefined, {
|
||||
...(reason ? { reason } : {}),
|
||||
...withRelTypes,
|
||||
});
|
||||
} catch (e: any) {
|
||||
const code = e.errcode || e.statusCode;
|
||||
// only show the dialog if failing for something other than a network error
|
||||
// (e.g. no errcode or statusCode) as in that case the redactions end up in the
|
||||
// detached queue and we show the room status bar to allow retry
|
||||
if (typeof code !== "undefined") {
|
||||
// display error message stating you couldn't delete this.
|
||||
Modal.createDialog(ErrorDialog, {
|
||||
title: _t("common|error"),
|
||||
description: _t("redact|error", { code }),
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
"mx_Dialog_confirmredact",
|
||||
);
|
||||
const cli = MatrixClientPeg.safeGet();
|
||||
const withRelTypes: Pick<IRedactOpts, "with_rel_types"> = {};
|
||||
|
||||
try {
|
||||
onCloseDialog?.();
|
||||
await cli.redactEvent(roomId, eventId, undefined, {
|
||||
...(reason ? { reason } : {}),
|
||||
...withRelTypes,
|
||||
});
|
||||
} catch (e: any) {
|
||||
const code = e.errcode || e.statusCode;
|
||||
// only show the dialog if failing for something other than a network error
|
||||
// (e.g. no errcode or statusCode) as in that case the redactions end up in the
|
||||
// detached queue and we show the room status bar to allow retry
|
||||
if (typeof code !== "undefined") {
|
||||
// display error message stating you couldn't delete this.
|
||||
Modal.createDialog(ErrorDialog, {
|
||||
title: _t("common|error"),
|
||||
description: _t("redact|error", { code }),
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user