From c9d664336e4aa31366d3d043753db6c0115c42ad Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Thu, 23 Feb 2017 21:28:15 -0800 Subject: [PATCH] simplify Attachments props --- .../src/components/TopicCard/Attachments.js | 26 +++++++++---------- frontend/src/components/TopicCard/index.js | 4 +-- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/frontend/src/components/TopicCard/Attachments.js b/frontend/src/components/TopicCard/Attachments.js index a45cf197..ee23915b 100644 --- a/frontend/src/components/TopicCard/Attachments.js +++ b/frontend/src/components/TopicCard/Attachments.js @@ -14,9 +14,8 @@ class Attachments extends Component { } componentDidMount = () => { - const { topic } = this.props embedly('on', 'card.rendered', this.embedlyCardRendered) - topic.get('link') && topic.get('link') !== '' && this.loadLink() + if (this.props.link) this.loadLink() } componentWillUnmount = () => { @@ -24,9 +23,8 @@ class Attachments extends Component { } componentDidUpdate = () => { - const { topic } = this.props const { embedlyLinkStarted } = this.state - !embedlyLinkStarted && topic.get('link') && topic.get('link') !== '' && this.loadLink() + !embedlyLinkStarted && this.props.link && this.loadLink() } embedlyCardRendered = (iframe, test) => { @@ -59,7 +57,8 @@ class Attachments extends Component { } loadLink = () => { - this.setState({embedlyLinkStarted: true}) + debugger + this.setState({ embedlyLinkStarted: true }) var e = embedly('card', document.getElementById('embedlyLink')) if (e && e.type === 'error') this.setState({embedlyLinkError: true}) } @@ -71,15 +70,14 @@ class Attachments extends Component { embedlyLinkError: false }) this.props.updateTopic({ link: null }) - $('.embedly-card').remove() // failsafe + $('div.embedly-card').after(``) + $('.embedly-card').remove() } render = () => { - const { topic, ActiveMapper } = this.props + const { link, authorizedToEdit } = this.props const { linkEdit, embedlyLinkLoaded, embedlyLinkStarted, embedlyLinkError } = this.state - - const authorizedToEdit = topic.authorizeToEdit(ActiveMapper) - const hasAttachment = topic.get('link') && topic.get('link') !== '' + const hasAttachment = !!link if (!hasAttachment && !authorizedToEdit) return null @@ -103,12 +101,12 @@ class Attachments extends Component { - {topic.get('link')} + {link} {embedlyLinkStarted && !embedlyLinkLoaded && !embedlyLinkError &&
loading...
} {authorizedToEdit && ( @@ -123,8 +121,8 @@ class Attachments extends Component { } Attachments.propTypes = { - topic: PropTypes.object, - ActiveMapper: PropTypes.object, + link: PropTypes.string, + authorizedToEdit: PropTypes.bool, updateTopic: PropTypes.func } diff --git a/frontend/src/components/TopicCard/index.js b/frontend/src/components/TopicCard/index.js index 548c6b4f..3c146ef2 100644 --- a/frontend/src/components/TopicCard/index.js +++ b/frontend/src/components/TopicCard/index.js @@ -36,8 +36,8 @@ class ReactTopicCard extends Component { authorizedToEdit={authorizedToEdit} onChange={this.props.updateTopic} /> -