Iterate Modal Widgets
Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
parent
00b1a03a3e
commit
16362440b3
3 changed files with 88 additions and 54 deletions
|
@ -19,7 +19,8 @@ import defaultDispatcher from "../dispatcher/dispatcher";
|
|||
import { ActionPayload } from "../dispatcher/payloads";
|
||||
import Modal, {IHandle, IModal} from "../Modal";
|
||||
import ModalWidgetDialog from "../components/views/dialogs/ModalWidgetDialog";
|
||||
import ActiveWidgetStore from "../stores/ActiveWidgetStore";
|
||||
import {WidgetMessagingStore} from "./widgets/WidgetMessagingStore";
|
||||
import {IModalWidgetOpenRequestData, IModalWidgetReturnData, Widget} from "matrix-widget-api";
|
||||
|
||||
interface IState {
|
||||
modal?: IModal<any>;
|
||||
|
@ -47,19 +48,17 @@ export class ModalWidgetStore extends AsyncStoreWithClient<IState> {
|
|||
return !this.modalInstance;
|
||||
};
|
||||
|
||||
public openModalWidget = (requestData: any, sourceWidgetId: string) => {
|
||||
public openModalWidget = (requestData: IModalWidgetOpenRequestData, sourceWidget: Widget) => {
|
||||
if (this.modalInstance) return;
|
||||
this.openSourceWidgetId = sourceWidgetId;
|
||||
this.openSourceWidgetId = sourceWidget.id;
|
||||
this.modalInstance = Modal.createTrackedDialog('Modal Widget', '', ModalWidgetDialog, {
|
||||
widgetDefinition: {...requestData},
|
||||
sourceWidgetId,
|
||||
onFinished: (success: boolean, data?: any) => {
|
||||
sourceWidgetId: sourceWidget.id,
|
||||
onFinished: (success: boolean, data?: IModalWidgetReturnData) => {
|
||||
if (!success) {
|
||||
this.closeModalWidget(sourceWidgetId, {
|
||||
"m.exited": true,
|
||||
});
|
||||
this.closeModalWidget(sourceWidget, { "m.exited": true });
|
||||
} else {
|
||||
this.closeModalWidget(sourceWidgetId, data);
|
||||
this.closeModalWidget(sourceWidget, data);
|
||||
}
|
||||
|
||||
this.openSourceWidgetId = null;
|
||||
|
@ -68,19 +67,19 @@ export class ModalWidgetStore extends AsyncStoreWithClient<IState> {
|
|||
});
|
||||
};
|
||||
|
||||
public closeModalWidget = (sourceWidgetId: string, data?: any) => {
|
||||
public closeModalWidget = (sourceWidget: Widget, data?: IModalWidgetReturnData) => {
|
||||
if (!this.modalInstance) return;
|
||||
if (this.openSourceWidgetId === sourceWidgetId) {
|
||||
if (this.openSourceWidgetId === sourceWidget.id) {
|
||||
this.openSourceWidgetId = null;
|
||||
this.modalInstance.close();
|
||||
this.modalInstance = null;
|
||||
|
||||
const sourceMessaging = ActiveWidgetStore.getWidgetMessaging(sourceWidgetId);
|
||||
const sourceMessaging = WidgetMessagingStore.instance.getMessaging(sourceWidget);
|
||||
if (!sourceMessaging) {
|
||||
console.error("No source widget messaging for modal widget");
|
||||
return;
|
||||
}
|
||||
sourceMessaging.sendModalCloseInfo(data);
|
||||
sourceMessaging.notifyModalWidgetClose(data);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue