diff options
author | Joram Wilander <jwawilander@gmail.com> | 2016-02-26 09:40:03 -0500 |
---|---|---|
committer | Joram Wilander <jwawilander@gmail.com> | 2016-02-26 09:40:03 -0500 |
commit | 63864c15dd614a5aef2444ef9335135845abbed4 (patch) | |
tree | 4f308fa0396630b56e79f1d99de456a5e8dfcf5e /web/react/components | |
parent | 42c78959a4c34b40afc755cfdd7326e0da891610 (diff) | |
parent | 8e3455943142da74be8b13632c0127f8248618cd (diff) | |
download | chat-63864c15dd614a5aef2444ef9335135845abbed4.tar.gz chat-63864c15dd614a5aef2444ef9335135845abbed4.tar.bz2 chat-63864c15dd614a5aef2444ef9335135845abbed4.zip |
Merge pull request #2027 from mozilla/PLT-1751
PLT-1751: Add the ability to collapse a link preview
Diffstat (limited to 'web/react/components')
-rw-r--r-- | web/react/components/post_body_additional_content.jsx | 40 |
1 files changed, 37 insertions, 3 deletions
diff --git a/web/react/components/post_body_additional_content.jsx b/web/react/components/post_body_additional_content.jsx index a76c59fb3..c2a928f3b 100644 --- a/web/react/components/post_body_additional_content.jsx +++ b/web/react/components/post_body_additional_content.jsx @@ -16,16 +16,28 @@ export default class PostBodyAdditionalContent extends React.Component { this.getSlackAttachment = this.getSlackAttachment.bind(this); this.getOEmbedProvider = this.getOEmbedProvider.bind(this); + this.generateEmbed = this.generateEmbed.bind(this); + this.toggleEmbedVisibility = this.toggleEmbedVisibility.bind(this); + + this.state = { + embedVisible: true + }; } - shouldComponentUpdate(nextProps) { + shouldComponentUpdate(nextProps, nextState) { if (!Utils.areObjectsEqual(nextProps.post, this.props.post)) { return true; } - + if (nextState.embedVisible !== this.state.embedVisible) { + return true; + } return false; } + toggleEmbedVisibility() { + this.setState({embedVisible: !this.state.embedVisible}); + } + getSlackAttachment() { let attachments = []; if (this.props.post.props && this.props.post.props.attachments) { @@ -51,7 +63,7 @@ export default class PostBodyAdditionalContent extends React.Component { return null; } - render() { + generateEmbed() { if (this.props.post.type === 'slack_attachment') { return this.getSlackAttachment(); } @@ -98,6 +110,28 @@ export default class PostBodyAdditionalContent extends React.Component { return null; } + + render() { + var generateEmbed = this.generateEmbed(); + if (generateEmbed) { + return ( + <div> + <a className='post__embed-visibility' + data-expanded={this.state.embedVisible} + aria-label='Toggle Embed Visibility' + onClick={this.toggleEmbedVisibility} + > + </a> + <div className='post__embed-container' + hidden={!this.state.embedVisible} + > + {generateEmbed} + </div> + </div> + ); + } + return null; + } } PostBodyAdditionalContent.propTypes = { |