From 8e3455943142da74be8b13632c0127f8248618cd Mon Sep 17 00:00:00 2001 From: Alan Mooiman Date: Thu, 25 Feb 2016 16:33:27 -0800 Subject: Add ability to toggle embed visibility --- .../components/post_body_additional_content.jsx | 40 ++++++++++++++++++++-- web/react/utils/constants.jsx | 4 +++ 2 files changed, 41 insertions(+), 3 deletions(-) (limited to 'web/react') 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 ( +
+ + + +
+ ); + } + return null; + } } PostBodyAdditionalContent.propTypes = { diff --git a/web/react/utils/constants.jsx b/web/react/utils/constants.jsx index 766a86686..0a4944708 100644 --- a/web/react/utils/constants.jsx +++ b/web/react/utils/constants.jsx @@ -479,6 +479,10 @@ export default { EMBED_PREVIEW: { label: 'embed_preview', description: 'Show preview snippet of links below message' + }, + EMBED_TOGGLE: { + label: 'embed_toggle', + description: 'Show toggle for all embed previews' } }, OVERLAY_TIME_DELAY: 400, -- cgit v1.2.3-1-g7c22