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;
|
||||
if (this.state.link) {
|
||||
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) {
|
||||
|
@ -31,7 +31,7 @@ module.exports = React.createClass({
|
||||
|
||||
propTypes: {
|
||||
link: React.PropTypes.string.isRequired,
|
||||
ts: React.PropTypes.number,
|
||||
mxEvent: React.PropTypes.object.isRequired,
|
||||
onWidgetLoad: React.PropTypes.func,
|
||||
},
|
||||
|
||||
@ -42,7 +42,13 @@ module.exports = React.createClass({
|
||||
},
|
||||
|
||||
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.props.onWidgetLoad();
|
||||
}, (error)=>{
|
||||
@ -60,6 +66,15 @@ module.exports = React.createClass({
|
||||
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() {
|
||||
var p = this.state.preview;
|
||||
if (!p) return <div/>;
|
||||
@ -93,6 +108,8 @@ module.exports = React.createClass({
|
||||
{ p["og:description"] }
|
||||
</div>
|
||||
</div>
|
||||
<img className="mx_LinkPreviewWidget_cancel" src="img/cancel.svg" width="18" height="18"
|
||||
onClick={ this.onCancelClick }/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user