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 &&