mirror of
https://github.com/vector-im/element-web.git
synced 2024-11-18 06:35:35 +08:00
support cancelling previews
This commit is contained in:
parent
f9c914c40e
commit
e61c99f7f3
@ -91,7 +91,7 @@ module.exports = React.createClass({
|
|||||||
var widget;
|
var widget;
|
||||||
if (this.state.link) {
|
if (this.state.link) {
|
||||||
var LinkPreviewWidget = sdk.getComponent('rooms.LinkPreviewWidget');
|
var LinkPreviewWidget = sdk.getComponent('rooms.LinkPreviewWidget');
|
||||||
widget = <LinkPreviewWidget link={ this.state.link } ts={ this.props.mxEvent.getTs() } onWidgetLoad={ this.props.onWidgetLoad }/>;
|
widget = <LinkPreviewWidget link={ this.state.link } mxEvent={ this.props.mxEvent } onWidgetLoad={ this.props.onWidgetLoad }/>;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (content.msgtype) {
|
switch (content.msgtype) {
|
||||||
|
@ -31,7 +31,7 @@ module.exports = React.createClass({
|
|||||||
|
|
||||||
propTypes: {
|
propTypes: {
|
||||||
link: React.PropTypes.string.isRequired,
|
link: React.PropTypes.string.isRequired,
|
||||||
ts: React.PropTypes.number,
|
mxEvent: React.PropTypes.object.isRequired,
|
||||||
onWidgetLoad: React.PropTypes.func,
|
onWidgetLoad: React.PropTypes.func,
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -42,7 +42,13 @@ module.exports = React.createClass({
|
|||||||
},
|
},
|
||||||
|
|
||||||
componentWillMount: function() {
|
componentWillMount: function() {
|
||||||
MatrixClientPeg.get().getUrlPreview(this.props.link, this.props.ts).then((res)=>{
|
if (global.localStorage) {
|
||||||
|
if (global.localStorage.getItem("hide_preview_" + this.props.mxEvent.getId()) === "1") {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
MatrixClientPeg.get().getUrlPreview(this.props.link, this.props.mxEvent.getTs()).then((res)=>{
|
||||||
this.setState({ preview: res });
|
this.setState({ preview: res });
|
||||||
this.props.onWidgetLoad();
|
this.props.onWidgetLoad();
|
||||||
}, (error)=>{
|
}, (error)=>{
|
||||||
@ -60,6 +66,15 @@ module.exports = React.createClass({
|
|||||||
linkifyElement(this.refs.description, linkifyMatrix.options);
|
linkifyElement(this.refs.description, linkifyMatrix.options);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
onCancelClick: function(event) {
|
||||||
|
this.setState({ preview: null });
|
||||||
|
// FIXME: persist this somewhere smarter than local storage
|
||||||
|
// FIXME: add to event contextual menu ability to unhide hidden previews
|
||||||
|
if (global.localStorage) {
|
||||||
|
global.localStorage.setItem("hide_preview_" + this.props.mxEvent.getId(), "1");
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
render: function() {
|
render: function() {
|
||||||
var p = this.state.preview;
|
var p = this.state.preview;
|
||||||
if (!p) return <div/>;
|
if (!p) return <div/>;
|
||||||
@ -93,6 +108,8 @@ module.exports = React.createClass({
|
|||||||
{ p["og:description"] }
|
{ p["og:description"] }
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<img className="mx_LinkPreviewWidget_cancel" src="img/cancel.svg" width="18" height="18"
|
||||||
|
onClick={ this.onCancelClick }/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user