Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
simplify loading
Browse files Browse the repository at this point in the history
Signed-off-by: Timo K <toger5@hotmail.de>
  • Loading branch information
toger5 committed Mar 1, 2024
1 parent 780ce48 commit 3f6402f
Showing 1 changed file with 4 additions and 14 deletions.
18 changes: 4 additions & 14 deletions src/components/views/elements/AppTile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ import { WidgetMessagingStore } from "../../../stores/widgets/WidgetMessagingSto
import { SdkContextClass } from "../../../contexts/SDKContext";
import { ModuleRunner } from "../../../modules/ModuleRunner";
import { parseUrl } from "../../../utils/UrlUtils";
import { setTimeout } from "matrix-js-sdk/src/realtime-callbacks";

interface IProps {
app: IWidget | IApp;
Expand Down Expand Up @@ -249,8 +250,9 @@ export default class AppTile extends React.Component<IProps, IState> {
private getNewState(newProps: IProps): IState {
return {
initialising: true, // True while we are mangling the widget URL
// True while the iframe content is loading
loading: true,
// Don't show loading at all if the widget is ready once the IFrame is loaded (waitForIframeLoad = true).
// We only need the loading screen if the widget sends a contentLoaded event (waitForIframeLoad = false).
loading: !this.props.waitForIframeLoad && !PersistedElement.isMounted(this.persistKey),
// Assume that widget has permission to load if we are the user who
// added it to the room, or if explicitly granted by the user
hasPermissionToLoad: this.hasPermissionToLoad(newProps),
Expand Down Expand Up @@ -312,7 +314,6 @@ export default class AppTile extends React.Component<IProps, IState> {
if (this.props.room) {
this.context.on(RoomEvent.MyMembership, this.onMyMembership);
}

this.allowedWidgetsWatchRef = SettingsStore.watchSetting("allowedWidgets", null, this.onAllowedWidgetsChange);
// Widget action listeners
this.dispatcherRef = dis.register(this.onAction);
Expand Down Expand Up @@ -353,7 +354,6 @@ export default class AppTile extends React.Component<IProps, IState> {

private setupSgListeners(): void {
this.sgWidget?.on("ready", this.onWidgetReady);
this.sgWidget?.on("preparing", this.onWidgetPreparing);
this.sgWidget?.on("error:preparing", this.updateRequiresClient);
// emits when the capabilities have been set up or changed
this.sgWidget?.on("capabilitiesNotified", this.updateRequiresClient);
Expand All @@ -362,7 +362,6 @@ export default class AppTile extends React.Component<IProps, IState> {
private stopSgListeners(): void {
if (!this.sgWidget) return;
this.sgWidget?.off("ready", this.onWidgetReady);
this.sgWidget?.off("preparing", this.onWidgetPreparing);
this.sgWidget.off("error:preparing", this.updateRequiresClient);
this.sgWidget.off("capabilitiesNotified", this.updateRequiresClient);
}
Expand Down Expand Up @@ -448,15 +447,6 @@ export default class AppTile extends React.Component<IProps, IState> {

this.sgWidget?.stopMessaging({ forceDestroy: true });
}
private onWidgetPreparing = (): void => {
if (this.props.waitForIframeLoad) {
// If the widget is configured to start immediately after the IFrame is loaded, (it does not have any custom initialization)
// we need to consider it ready now since it might not even use the widget api.
this.onWidgetReady();
}
// If waitForIframeLoad = false. We do nothing here. The widget is responsible to send a content_loaded action
// and the messaging will emit "ready" (-> this will call onWidgetReady)
};
private onWidgetReady = (): void => {
this.setState({ loading: false });
};
Expand Down

0 comments on commit 3f6402f

Please sign in to comment.