bug fix: crashes when switching topics with open <InfoView>

This commit is contained in:
or-else
2018-05-16 11:36:54 -07:00
parent 2e619d3fb8
commit eb3ccf7b1e
+16 -19
View File
@@ -2501,6 +2501,7 @@
var InfoView = React.createClass({ var InfoView = React.createClass({
getInitialState: function() { getInitialState: function() {
return { return {
topic: null,
owner: false, owner: false,
admin: false, admin: false,
sharer: false, sharer: false,
@@ -2539,24 +2540,23 @@
return; return;
} }
this.previousMetaDesc = topic.onMetaDesc; if (this.previousMetaDesc != topic.onMetaDesc) {
topic.onMetaDesc = this.onMetaDesc; this.previousMetaDesc = topic.onMetaDesc;
topic.onMetaDesc = this.onMetaDesc;
this.previousSubsUpdated = topic.onSubsUpdated; this.previousSubsUpdated = topic.onSubsUpdated;
topic.onSubsUpdated = this.onSubsUpdated; topic.onSubsUpdated = this.onSubsUpdated;
if (topic.getType() === "grp") { if (topic.getType() === "grp") {
this.previousTagsUpdated = topic.onTagsUpdated; this.previousTagsUpdated = topic.onTagsUpdated;
topic.onTagsUpdated = this.onTagsUpdated; topic.onTagsUpdated = this.onTagsUpdated;
} else { } else {
this.previousTagsUpdated = undefined; this.previousTagsUpdated = undefined;
}
} }
this.resetInfoView(topic, props, true); if (this.state.topic != props.topic) {
}, this.setState({topic: props.topic});
resetInfoView: function(topic, props, forced) {
if (forced || this.props.topic != props.topic) {
this.resetDesc(topic, props); this.resetDesc(topic, props);
this.resetSubs(topic, props); this.resetSubs(topic, props);
@@ -2571,17 +2571,14 @@
if (!topic) { if (!topic) {
return; return;
} }
this.setState({topic: null});
topic.onMetaDesc = this.previousMetaDesc; topic.onMetaDesc = this.previousMetaDesc;
topic.onSubsUpdated = this.previousSubsUpdated; topic.onSubsUpdated = this.previousSubsUpdated;
topic.onTagsUpdated = this.previousTagsUpdated; topic.onTagsUpdated = this.previousTagsUpdated;
}, },
componentWillReceiveProps: function(nextProps) { componentWillReceiveProps: function(nextProps) {
var topic = Tinode.getTopic(nextProps.topic); this.initInfoView(nextProps);
if (!topic) {
return;
}
this.resetInfoView(topic, nextProps);
}, },
resetSubs: function(topic, props) { resetSubs: function(topic, props) {