Merge pull request #2862 from matrix-org/travis/stickerpicker/remount

Don't re-init the stickerpicker unless something actually changes
This commit is contained in:
Travis Ralston 2019-04-04 09:46:38 -06:00 committed by GitHub
commit a61ab4eb4e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 14 additions and 8 deletions

View file

@ -116,10 +116,8 @@ export default class FromWidgetPostMessageApi {
const origin = u.protocol + '//' + u.host; const origin = u.protocol + '//' + u.host;
if (this.widgetMessagingEndpoints && this.widgetMessagingEndpoints.length > 0) { if (this.widgetMessagingEndpoints && this.widgetMessagingEndpoints.length > 0) {
const length = this.widgetMessagingEndpoints.length; const length = this.widgetMessagingEndpoints.length;
this.widgetMessagingEndpoints = this.widgetMessagingEndpoints. this.widgetMessagingEndpoints = this.widgetMessagingEndpoints
filter(function(endpoint) { .filter((endpoint) => endpoint.widgetId !== widgetId || endpoint.endpointUrl !== origin);
return (endpoint.widgetId != widgetId || endpoint.endpointUrl != origin);
});
return (length > this.widgetMessagingEndpoints.length); return (length > this.widgetMessagingEndpoints.length);
} }
return false; return false;

View file

@ -339,9 +339,7 @@ export default class AppTile extends React.Component {
// Destroy the old widget messaging before starting it back up again. Some widgets // Destroy the old widget messaging before starting it back up again. Some widgets
// have startup routines that run when they are loaded, so we just need to reinitialize // have startup routines that run when they are loaded, so we just need to reinitialize
// the messaging for them. // the messaging for them.
if (ActiveWidgetStore.getWidgetMessaging(this.props.id)) { ActiveWidgetStore.delWidgetMessaging(this.props.id);
ActiveWidgetStore.delWidgetMessaging(this.props.id);
}
this._setupWidgetMessaging(); this._setupWidgetMessaging();
ActiveWidgetStore.setRoomId(this.props.id, this.props.room.roomId); ActiveWidgetStore.setRoomId(this.props.id, this.props.room.roomId);

View file

@ -37,6 +37,8 @@ const STICKERPICKER_Z_INDEX = 3500;
const PERSISTED_ELEMENT_KEY = "stickerPicker"; const PERSISTED_ELEMENT_KEY = "stickerPicker";
export default class Stickerpicker extends React.Component { export default class Stickerpicker extends React.Component {
static currentWidget;
constructor(props) { constructor(props) {
super(props); super(props);
this._onShowStickersClick = this._onShowStickersClick.bind(this); this._onShowStickersClick = this._onShowStickersClick.bind(this);
@ -130,8 +132,13 @@ export default class Stickerpicker extends React.Component {
_updateWidget() { _updateWidget() {
const stickerpickerWidget = WidgetUtils.getStickerpickerWidgets()[0]; const stickerpickerWidget = WidgetUtils.getStickerpickerWidgets()[0];
if (!stickerpickerWidget) {
Stickerpicker.currentWidget = null;
this.setState({stickerpickerWidget: null, widgetId: null});
return;
}
const currentWidget = this.state.stickerpickerWidget; const currentWidget = Stickerpicker.currentWidget;
let currentUrl = null; let currentUrl = null;
if (currentWidget && currentWidget.content && currentWidget.content.url) { if (currentWidget && currentWidget.content && currentWidget.content.url) {
currentUrl = currentWidget.content.url; currentUrl = currentWidget.content.url;
@ -147,6 +154,7 @@ export default class Stickerpicker extends React.Component {
PersistedElement.destroyElement(PERSISTED_ELEMENT_KEY); PersistedElement.destroyElement(PERSISTED_ELEMENT_KEY);
} }
Stickerpicker.currentWidget = stickerpickerWidget;
this.setState({ this.setState({
stickerpickerWidget, stickerpickerWidget,
widgetId: stickerpickerWidget ? stickerpickerWidget.id : null, widgetId: stickerpickerWidget ? stickerpickerWidget.id : null,

View file

@ -112,6 +112,8 @@ class ActiveWidgetStore extends EventEmitter {
} }
setWidgetMessaging(widgetId, wm) { setWidgetMessaging(widgetId, wm) {
// Stop any existing widget messaging first
this.delWidgetMessaging(widgetId);
this._widgetMessagingByWidgetId[widgetId] = wm; this._widgetMessagingByWidgetId[widgetId] = wm;
this.emit('update'); this.emit('update');
} }