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);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -32,6 +32,7 @@ import {
|
|||
Widget,
|
||||
WidgetApiToWidgetAction,
|
||||
WidgetApiFromWidgetAction,
|
||||
IModalWidgetOpenRequest,
|
||||
} from "matrix-widget-api";
|
||||
import { StopGapWidgetDriver } from "./StopGapWidgetDriver";
|
||||
import { EventEmitter } from "events";
|
||||
|
@ -49,6 +50,7 @@ import defaultDispatcher from "../../dispatcher/dispatcher";
|
|||
import { ElementWidgetActions } from "./ElementWidgetActions";
|
||||
import Modal from "../../Modal";
|
||||
import WidgetOpenIDPermissionsDialog from "../../components/views/dialogs/WidgetOpenIDPermissionsDialog";
|
||||
import {ModalWidgetStore} from "../ModalWidgetStore";
|
||||
|
||||
// TODO: Destroy all of this code
|
||||
|
||||
|
@ -201,7 +203,7 @@ export class StopGapWidget extends EventEmitter {
|
|||
}
|
||||
|
||||
private onOpenIdReq = async (ev: CustomEvent<IGetOpenIDActionRequest>) => {
|
||||
if (ev?.detail?.widgetId !== this.widgetId) return;
|
||||
ev.preventDefault();
|
||||
|
||||
const rawUrl = this.appTileProps.app.url;
|
||||
const widgetSecurityKey = WidgetUtils.getWidgetSecurityKey(this.widgetId, rawUrl, this.appTileProps.userWidget);
|
||||
|
@ -249,6 +251,20 @@ export class StopGapWidget extends EventEmitter {
|
|||
});
|
||||
};
|
||||
|
||||
private onOpenModal = async (ev: CustomEvent<IModalWidgetOpenRequest>) => {
|
||||
ev.preventDefault();
|
||||
if (ModalWidgetStore.instance.canOpenModalWidget()) {
|
||||
ModalWidgetStore.instance.openModalWidget(ev.detail.data, this.mockWidget);
|
||||
this.messaging.transport.reply(ev.detail, {}); // ack
|
||||
} else {
|
||||
this.messaging.transport.reply(ev.detail, {
|
||||
error: {
|
||||
message: "Unable to open modal at this time",
|
||||
},
|
||||
})
|
||||
}
|
||||
};
|
||||
|
||||
public start(iframe: HTMLIFrameElement) {
|
||||
if (this.started) return;
|
||||
const driver = new StopGapWidgetDriver( this.appTileProps.whitelistCapabilities || []);
|
||||
|
@ -256,6 +272,7 @@ export class StopGapWidget extends EventEmitter {
|
|||
this.messaging.on("preparing", () => this.emit("preparing"));
|
||||
this.messaging.on("ready", () => this.emit("ready"));
|
||||
this.messaging.on(`action:${WidgetApiFromWidgetAction.GetOpenIDCredentials}`, this.onOpenIdReq);
|
||||
this.messaging.on(`action:${WidgetApiFromWidgetAction.OpenModalWidget}`, this.onOpenModal);
|
||||
WidgetMessagingStore.instance.storeMessaging(this.mockWidget, this.messaging);
|
||||
|
||||
if (!this.appTileProps.userWidget && this.appTileProps.room) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue