Iterate Modal Widgets
Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
parent
55e6ff9b2d
commit
ad15747c21
2 changed files with 27 additions and 9 deletions
|
@ -18,7 +18,12 @@ limitations under the License.
|
||||||
require("./index.scss");
|
require("./index.scss");
|
||||||
|
|
||||||
import * as qs from 'querystring';
|
import * as qs from 'querystring';
|
||||||
import {ModalButtonKind, WidgetApi, WidgetApiToWidgetAction} from 'matrix-widget-api';
|
import {
|
||||||
|
ModalButtonKind,
|
||||||
|
WidgetApi,
|
||||||
|
WidgetApiToWidgetAction,
|
||||||
|
IModalWidgetCloseNotificationRequest,
|
||||||
|
} from 'matrix-widget-api';
|
||||||
|
|
||||||
let widgetApi: WidgetApi;
|
let widgetApi: WidgetApi;
|
||||||
(async function() {
|
(async function() {
|
||||||
|
@ -38,9 +43,13 @@ let widgetApi: WidgetApi;
|
||||||
const parentOrigin = new URL(qsParam('parentUrl')).origin;
|
const parentOrigin = new URL(qsParam('parentUrl')).origin;
|
||||||
widgetApi = new WidgetApi(qsParam("widgetId"), parentOrigin);
|
widgetApi = new WidgetApi(qsParam("widgetId"), parentOrigin);
|
||||||
|
|
||||||
widgetApi.addEventListener(WidgetApiToWidgetAction.CloseModalWidget, (req: CustomEvent) => {
|
widgetApi.on(`action:${WidgetApiToWidgetAction.CloseModalWidget}`,
|
||||||
document.getElementById("answer").innerText = "Response from Modal: " + JSON.stringify(req.detail);
|
(ev: CustomEvent<IModalWidgetCloseNotificationRequest>) => {
|
||||||
});
|
ev.preventDefault();
|
||||||
|
document.getElementById("answer").innerText = "Response from Modal: " + JSON.stringify(ev.detail);
|
||||||
|
widgetApi.transport.reply(ev.detail, {}); // ack
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
widgetApi.start();
|
widgetApi.start();
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,12 @@ limitations under the License.
|
||||||
require("./index.scss");
|
require("./index.scss");
|
||||||
|
|
||||||
import * as qs from 'querystring';
|
import * as qs from 'querystring';
|
||||||
import {WidgetApi, WidgetApiToWidgetAction, IWidgetApiRequest} from 'matrix-widget-api';
|
import {
|
||||||
|
WidgetApi,
|
||||||
|
WidgetApiToWidgetAction,
|
||||||
|
IModalWidgetButtonClickedRequest,
|
||||||
|
IModalWidgetOpenRequest,
|
||||||
|
} from 'matrix-widget-api';
|
||||||
|
|
||||||
let widgetApi: WidgetApi;
|
let widgetApi: WidgetApi;
|
||||||
(async function() {
|
(async function() {
|
||||||
|
@ -38,22 +43,26 @@ let widgetApi: WidgetApi;
|
||||||
const parentOrigin = new URL(qsParam('parentUrl')).origin;
|
const parentOrigin = new URL(qsParam('parentUrl')).origin;
|
||||||
widgetApi = new WidgetApi(qsParam("widgetId"), parentOrigin);
|
widgetApi = new WidgetApi(qsParam("widgetId"), parentOrigin);
|
||||||
|
|
||||||
widgetApi.addEventListener(
|
widgetApi.on(
|
||||||
`action:${WidgetApiToWidgetAction.ButtonClicked}`,
|
`action:${WidgetApiToWidgetAction.ButtonClicked}`,
|
||||||
(ev: CustomEvent<IWidgetApiRequest>) => {
|
(ev: CustomEvent<IModalWidgetButtonClickedRequest>) => {
|
||||||
|
ev.preventDefault();
|
||||||
console.log("@@ clickety", ev.detail);
|
console.log("@@ clickety", ev.detail);
|
||||||
document.getElementById("button").innerText = "BUTTON CLICKED: " + JSON.stringify(ev.detail.data);
|
document.getElementById("button").innerText = "BUTTON CLICKED: " + JSON.stringify(ev.detail.data);
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
widgetApi.closeModalWidget(ev.detail.data);
|
widgetApi.closeModalWidget(ev.detail.data);
|
||||||
}, 3000);
|
}, 3000);
|
||||||
|
widgetApi.transport.reply(ev.detail, {}); // ack
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
widgetApi.addEventListener(
|
widgetApi.on(
|
||||||
`action:${WidgetApiToWidgetAction.WidgetConfig}`,
|
`action:${WidgetApiToWidgetAction.WidgetConfig}`,
|
||||||
(ev: CustomEvent<IWidgetApiRequest>) => {
|
(ev: CustomEvent<IModalWidgetOpenRequest>) => {
|
||||||
|
ev.preventDefault();
|
||||||
console.log("Got widget config: ", ev.detail.data);
|
console.log("Got widget config: ", ev.detail.data);
|
||||||
document.getElementById("question").innerText = "INIT PARAMS: " + JSON.stringify(ev.detail.data);
|
document.getElementById("question").innerText = "INIT PARAMS: " + JSON.stringify(ev.detail.data);
|
||||||
|
widgetApi.transport.reply(ev.detail, {}); // ack
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
widgetApi.start();
|
widgetApi.start();
|
||||||
|
|
Loading…
Add table
Reference in a new issue