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
@@ -119,7 +119,7 @@ export class DialogOpener {
|
||||
break;
|
||||
case Action.OpenAddToExistingSpaceDialog: {
|
||||
const space = payload.space;
|
||||
Modal.createDialog(
|
||||
const { finished } = Modal.createDialog(
|
||||
AddExistingToSpaceDialog,
|
||||
{
|
||||
onCreateRoomClick: (ev: ButtonEvent) => {
|
||||
@@ -128,14 +128,14 @@ export class DialogOpener {
|
||||
},
|
||||
onAddSubspaceClick: () => showAddExistingSubspace(space),
|
||||
space,
|
||||
onFinished: (added: boolean) => {
|
||||
if (added && SdkContextClass.instance.roomViewStore.getRoomId() === space.roomId) {
|
||||
defaultDispatcher.fire(Action.UpdateSpaceHierarchy);
|
||||
}
|
||||
},
|
||||
},
|
||||
"mx_AddExistingToSpaceDialog_wrapper",
|
||||
);
|
||||
finished.then(([added]) => {
|
||||
if (added && SdkContextClass.instance.roomViewStore.getRoomId() === space.roomId) {
|
||||
defaultDispatcher.fire(Action.UpdateSpaceHierarchy);
|
||||
}
|
||||
});
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -171,20 +171,20 @@ export async function leaveRoomBehaviour(
|
||||
}
|
||||
|
||||
export const leaveSpace = (space: Room): void => {
|
||||
Modal.createDialog(
|
||||
const { finished } = Modal.createDialog(
|
||||
LeaveSpaceDialog,
|
||||
{
|
||||
space,
|
||||
onFinished: async (leave: boolean, rooms: Room[]): Promise<void> => {
|
||||
if (!leave) return;
|
||||
await bulkSpaceBehaviour(space, rooms, (room) => leaveRoomBehaviour(space.client, room.roomId));
|
||||
|
||||
dis.dispatch<AfterLeaveRoomPayload>({
|
||||
action: Action.AfterLeaveRoom,
|
||||
room_id: space.roomId,
|
||||
});
|
||||
},
|
||||
},
|
||||
"mx_LeaveSpaceDialog_wrapper",
|
||||
);
|
||||
finished.then(async ([leave, rooms]) => {
|
||||
if (!leave) return;
|
||||
await bulkSpaceBehaviour(space, rooms!, (room) => leaveRoomBehaviour(space.client, room.roomId));
|
||||
|
||||
dis.dispatch<AfterLeaveRoomPayload>({
|
||||
action: Action.AfterLeaveRoom,
|
||||
room_id: space.roomId,
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
@@ -75,7 +75,7 @@ export const showCreateNewRoom = async (space: Room, type?: RoomType): Promise<b
|
||||
});
|
||||
const [shouldCreate, opts] = await modal.finished;
|
||||
if (shouldCreate) {
|
||||
await createRoom(space.client, opts);
|
||||
await createRoom(space.client, opts!);
|
||||
}
|
||||
return !!shouldCreate;
|
||||
};
|
||||
@@ -106,35 +106,35 @@ export const showSpaceInvite = (space: Room, initialText = ""): void => {
|
||||
};
|
||||
|
||||
export const showAddExistingSubspace = (space: Room): void => {
|
||||
Modal.createDialog(
|
||||
const { finished } = Modal.createDialog(
|
||||
AddExistingSubspaceDialog,
|
||||
{
|
||||
space,
|
||||
onCreateSubspaceClick: () => showCreateNewSubspace(space),
|
||||
onFinished: (added: boolean) => {
|
||||
if (added && SdkContextClass.instance.roomViewStore.getRoomId() === space.roomId) {
|
||||
defaultDispatcher.fire(Action.UpdateSpaceHierarchy);
|
||||
}
|
||||
},
|
||||
},
|
||||
"mx_AddExistingToSpaceDialog_wrapper",
|
||||
);
|
||||
finished.then(([added]) => {
|
||||
if (added && SdkContextClass.instance.roomViewStore.getRoomId() === space.roomId) {
|
||||
defaultDispatcher.fire(Action.UpdateSpaceHierarchy);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
export const showCreateNewSubspace = (space: Room): void => {
|
||||
Modal.createDialog(
|
||||
const { finished } = Modal.createDialog(
|
||||
CreateSubspaceDialog,
|
||||
{
|
||||
space,
|
||||
onAddExistingSpaceClick: () => showAddExistingSubspace(space),
|
||||
onFinished: (added: boolean) => {
|
||||
if (added && SdkContextClass.instance.roomViewStore.getRoomId() === space.roomId) {
|
||||
defaultDispatcher.fire(Action.UpdateSpaceHierarchy);
|
||||
}
|
||||
},
|
||||
},
|
||||
"mx_CreateSubspaceDialog_wrapper",
|
||||
);
|
||||
finished.then(([added]) => {
|
||||
if (added && SdkContextClass.instance.roomViewStore.getRoomId() === space.roomId) {
|
||||
defaultDispatcher.fire(Action.UpdateSpaceHierarchy);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
export const bulkSpaceBehaviour = async (
|
||||
|
||||
Reference in New Issue
Block a user