Make widgets not reload (persistent) between center and top container (#7575)
This commit is contained in:
parent
e28d2a2299
commit
9d9b77d5e1
6 changed files with 108 additions and 81 deletions
|
@ -255,8 +255,11 @@ export class StopGapWidget extends EventEmitter {
|
|||
});
|
||||
}
|
||||
};
|
||||
|
||||
public start(iframe: HTMLIFrameElement) {
|
||||
/**
|
||||
* This starts the messaging for the widget if it is not in the state `started` yet.
|
||||
* @param iframe the iframe the widget should use
|
||||
*/
|
||||
public startMessaging(iframe: HTMLIFrameElement): any {
|
||||
if (this.started) return;
|
||||
const allowedCapabilities = this.appTileProps.whitelistCapabilities || [];
|
||||
const driver = new StopGapWidgetDriver(allowedCapabilities, this.mockWidget, this.kind, this.roomId);
|
||||
|
@ -407,7 +410,12 @@ export class StopGapWidget extends EventEmitter {
|
|||
}
|
||||
}
|
||||
|
||||
public stop(opts = { forceDestroy: false }) {
|
||||
/**
|
||||
* Stops the widget messaging for if it is started. Skips stopping if it is an active
|
||||
* widget.
|
||||
* @param opts
|
||||
*/
|
||||
public stopMessaging(opts = { forceDestroy: false }) {
|
||||
if (!opts?.forceDestroy && ActiveWidgetStore.instance.getPersistentWidgetId() === this.mockWidget.id) {
|
||||
logger.log("Skipping destroy - persistent widget");
|
||||
return;
|
||||
|
|
|
@ -27,6 +27,8 @@ import { SettingLevel } from "../../settings/SettingLevel";
|
|||
import { arrayFastClone } from "../../utils/arrays";
|
||||
import { UPDATE_EVENT } from "../AsyncStore";
|
||||
import { compare } from "../../utils/strings";
|
||||
import RightPanelStore from "../right-panel/RightPanelStore";
|
||||
import { RightPanelPhases } from "../right-panel/RightPanelStorePhases";
|
||||
|
||||
export const WIDGET_LAYOUT_EVENT_TYPE = "io.element.widgets.layout";
|
||||
|
||||
|
@ -351,6 +353,22 @@ export class WidgetLayoutStore extends ReadyWatchingStore {
|
|||
return this.getContainerWidgets(room, container).some(w => w.id === widget.id);
|
||||
}
|
||||
|
||||
public isVisibleOnScreen(room: Room, widgetId: string) {
|
||||
const wId = widgetId;
|
||||
const inRightPanel =
|
||||
(RightPanelStore.instance.currentCard.phase == RightPanelPhases.Widget &&
|
||||
wId == RightPanelStore.instance.currentCard.state?.widgetId);
|
||||
const inCenterContainer =
|
||||
this.getContainerWidgets(room, Container.Center).some((app) => app.id == wId);
|
||||
const inTopContainer =
|
||||
this.getContainerWidgets(room, Container.Top).some(app => app.id == wId);
|
||||
|
||||
// The widget should only be shown as a persistent app (in a floating pip container) if it is not visible on screen
|
||||
// either, because we are viewing a different room OR because it is in none of the possible containers of the room view.
|
||||
const isVisibleOnScreen = (inRightPanel || inCenterContainer || inTopContainer);
|
||||
return isVisibleOnScreen;
|
||||
}
|
||||
|
||||
public canAddToContainer(room: Room, container: Container): boolean {
|
||||
switch (container) {
|
||||
case Container.Top: return this.getContainerWidgets(room, container).length < MAX_PINNED;
|
||||
|
@ -440,7 +458,8 @@ export class WidgetLayoutStore extends ReadyWatchingStore {
|
|||
public moveToContainer(room: Room, widget: IApp, toContainer: Container) {
|
||||
const allWidgets = this.getAllWidgets(room);
|
||||
if (!allWidgets.some(([w]) => w.id === widget.id)) return; // invalid
|
||||
// Prepare other containers (potentially move widgets to obay the following rules)
|
||||
// Prepare other containers (potentially move widgets to obey the following rules)
|
||||
const newLayout = {};
|
||||
switch (toContainer) {
|
||||
case Container.Right:
|
||||
// new "right" widget
|
||||
|
@ -448,24 +467,25 @@ export class WidgetLayoutStore extends ReadyWatchingStore {
|
|||
case Container.Center:
|
||||
// new "center" widget => all other widgets go into "right"
|
||||
for (const w of this.getContainerWidgets(room, Container.Top)) {
|
||||
this.moveToContainer(room, w, Container.Right);
|
||||
newLayout[w.id] = { container: Container.Right };
|
||||
}
|
||||
for (const w of this.getContainerWidgets(room, Container.Center)) {
|
||||
this.moveToContainer(room, w, Container.Right);
|
||||
newLayout[w.id] = { container: Container.Right };
|
||||
}
|
||||
break;
|
||||
case Container.Top:
|
||||
// new "top" widget => the center widget moves into "right"
|
||||
if (this.hasMaximisedWidget(room)) {
|
||||
this.moveToContainer(room, this.getContainerWidgets(room, Container.Center)[0], Container.Right);
|
||||
const centerWidget = this.getContainerWidgets(room, Container.Center)[0];
|
||||
newLayout[centerWidget.id] = { container: Container.Right };
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
// move widgets into requested container.
|
||||
this.updateUserLayout(room, {
|
||||
[widget.id]: { container: toContainer },
|
||||
});
|
||||
newLayout[widget.id] = { container: toContainer };
|
||||
|
||||
// move widgets into requested containers.
|
||||
this.updateUserLayout(room, newLayout);
|
||||
}
|
||||
|
||||
public hasMaximisedWidget(room: Room) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue