1
0
mirror of https://github.com/matrix-org/matrix-react-sdk.git synced 2025-07-31 13:44:28 +03:00

add the concept of eventTileOps for managing widget visibility based on vdh's PR feedback

This commit is contained in:
Matthew Hodgson
2016-04-08 21:42:29 +01:00
parent 23d6edbf63
commit 6c372d37f7
3 changed files with 26 additions and 21 deletions

View File

@ -50,10 +50,6 @@ module.exports = React.createClass({
link: null,
// track whether the preview widget is hidden
// we can't directly use mxEvent's widgetHidden property
// as shouldComponentUpdate needs to be able to do before & after
// comparisons of the property (and we don't pass it in as a top
// level prop to avoid bloating the number of props flying around)
widgetHidden: false,
};
},
@ -68,8 +64,6 @@ module.exports = React.createClass({
// lazy-load the hidden state of the preview widget from localstorage
if (global.localStorage) {
var hidden = global.localStorage.getItem("hide_preview_" + this.props.mxEvent.getId());
// XXX: we're gutwrenching mxEvent here by setting our own custom property on it
this.props.mxEvent.widgetHidden = hidden;
this.setState({ widgetHidden: hidden });
}
}
@ -84,11 +78,7 @@ module.exports = React.createClass({
nextProps.highlights !== this.props.highlights ||
nextProps.highlightLink !== this.props.highlightLink ||
nextState.link !== this.state.link ||
nextProps.mxEvent.widgetHidden !== this.state.widgetHidden);
},
componentWillUpdate: function(nextProps, nextState) {
this.setState({ widgetHidden: nextProps.mxEvent.widgetHidden });
nextState.widgetHidden !== this.state.widgetHidden);
},
findLink: function(nodes) {
@ -104,8 +94,6 @@ module.exports = React.createClass({
},
onCancelClick: function(event) {
// XXX: we're gutwrenching mxEvent here by setting our own custom property on it
this.props.mxEvent.widgetHidden = true;
this.setState({ widgetHidden: true });
// FIXME: persist this somewhere smarter than local storage
if (global.localStorage) {
@ -114,6 +102,19 @@ module.exports = React.createClass({
this.forceUpdate();
},
getEventTileOps: function() {
var self = this;
return {
isWidgetHidden: function() {
return self.state.widgetHidden;
},
unhideWidget: function() {
self.setState({ widgetHidden: false });
},
}
},
render: function() {
var mxEvent = this.props.mxEvent;
var content = mxEvent.getContent();