Discard old sticker picker when the URL changes
Fixes https://github.com/vector-im/riot-web/issues/7547pull/21833/head
parent
d4b05a54e5
commit
a397f333d7
|
@ -25,6 +25,7 @@ import dis from '../../../dispatcher';
|
||||||
import AccessibleButton from '../elements/AccessibleButton';
|
import AccessibleButton from '../elements/AccessibleButton';
|
||||||
import WidgetUtils from '../../../utils/WidgetUtils';
|
import WidgetUtils from '../../../utils/WidgetUtils';
|
||||||
import ActiveWidgetStore from '../../../stores/ActiveWidgetStore';
|
import ActiveWidgetStore from '../../../stores/ActiveWidgetStore';
|
||||||
|
import PersistedElement from "../elements/PersistedElement";
|
||||||
|
|
||||||
const widgetType = 'm.stickerpicker';
|
const widgetType = 'm.stickerpicker';
|
||||||
|
|
||||||
|
@ -32,6 +33,9 @@ const widgetType = 'm.stickerpicker';
|
||||||
// above it, so it needs a greater z-index than the ContextMenu
|
// above it, so it needs a greater z-index than the ContextMenu
|
||||||
const STICKERPICKER_Z_INDEX = 5000;
|
const STICKERPICKER_Z_INDEX = 5000;
|
||||||
|
|
||||||
|
// Key to store the widget's AppTile under in PersistedElement
|
||||||
|
const PERSISTED_ELEMENT_KEY = "stickerPicker";
|
||||||
|
|
||||||
export default class Stickerpicker extends React.Component {
|
export default class Stickerpicker extends React.Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
|
@ -126,6 +130,23 @@ export default class Stickerpicker extends React.Component {
|
||||||
|
|
||||||
_updateWidget() {
|
_updateWidget() {
|
||||||
const stickerpickerWidget = WidgetUtils.getStickerpickerWidgets()[0];
|
const stickerpickerWidget = WidgetUtils.getStickerpickerWidgets()[0];
|
||||||
|
|
||||||
|
const currentWidget = this.state.stickerpickerWidget;
|
||||||
|
let currentUrl = null;
|
||||||
|
if (currentWidget && currentWidget.content && currentWidget.content.url) {
|
||||||
|
currentUrl = currentWidget.content.url;
|
||||||
|
}
|
||||||
|
|
||||||
|
let newUrl = null;
|
||||||
|
if (stickerpickerWidget && stickerpickerWidget.content && stickerpickerWidget.content.url) {
|
||||||
|
newUrl = stickerpickerWidget.content.url;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (newUrl !== currentUrl) {
|
||||||
|
// Destroy the existing frame so a new one can be created
|
||||||
|
PersistedElement.destroyElement(PERSISTED_ELEMENT_KEY);
|
||||||
|
}
|
||||||
|
|
||||||
this.setState({
|
this.setState({
|
||||||
stickerpickerWidget,
|
stickerpickerWidget,
|
||||||
widgetId: stickerpickerWidget ? stickerpickerWidget.id : null,
|
widgetId: stickerpickerWidget ? stickerpickerWidget.id : null,
|
||||||
|
@ -211,7 +232,7 @@ export default class Stickerpicker extends React.Component {
|
||||||
width: this.popoverWidth,
|
width: this.popoverWidth,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<PersistedElement persistKey="stickerPicker" style={{zIndex: STICKERPICKER_Z_INDEX}}>
|
<PersistedElement persistKey={PERSISTED_ELEMENT_KEY} style={{zIndex: STICKERPICKER_Z_INDEX}}>
|
||||||
<AppTile
|
<AppTile
|
||||||
id={stickerpickerWidget.id}
|
id={stickerpickerWidget.id}
|
||||||
url={stickerpickerWidget.content.url}
|
url={stickerpickerWidget.content.url}
|
||||||
|
|
Loading…
Reference in New Issue