diff --git a/frontend/src/components/TopicCard/Attachments.js b/frontend/src/components/TopicCard/Attachments.js index 2d94a8c7..2f29b53a 100644 --- a/frontend/src/components/TopicCard/Attachments.js +++ b/frontend/src/components/TopicCard/Attachments.js @@ -61,7 +61,7 @@ class Attachments extends Component { loadLink = () => { this.setState({embedlyLinkStarted: true}) var e = embedly('card', document.getElementById('embedlyLink')) - if (e.type === 'error') this.setState({embedlyLinkError: true}) + if (e && e.type === 'error') this.setState({embedlyLinkError: true}) } removeLink = () => { @@ -76,39 +76,48 @@ class Attachments extends Component { render = () => { const { topic, ActiveMapper } = this.props const { linkEdit, embedlyLinkLoaded, embedlyLinkStarted, embedlyLinkError } = this.state - var authorizedToEdit = topic.authorizeToEdit(ActiveMapper) + const authorizedToEdit = topic.authorizeToEdit(ActiveMapper) const hasAttachment = topic.get('link') && topic.get('link') !== '' - if (hasAttachment) { - return ( -
- - {topic.get('link')} - - {embedlyLinkStarted && !embedlyLinkLoaded && !embedlyLinkError &&
loading...
} - {authorizedToEdit &&
} -
- ) - } else if (authorizedToEdit) { - return ( -
-
-
-
- this.linkInput = input} - placeholder="Enter or paste a link" - value={linkEdit} - onChange={this.onLinkChangeHandler} - onKeyUp={this.onLinkKeyUpHandler}> - {linkEdit &&
} -
+ if (!hasAttachment && !authorizedToEdit) return null + + const className = hasAttachment + ? `embeds ${embedlyLinkLoaded ? '' : 'nonEmbedlyLink'}` + : 'attachments' + + return ( +
+
+
+
+ this.linkInput = input} + placeholder="Enter or paste a link" + value={linkEdit} + onChange={this.onLinkChangeHandler} + onKeyUp={this.onLinkKeyUpHandler}> + {linkEdit &&
}
- ) - } else { - return null - } + + {topic.get('link')} + + {embedlyLinkStarted && !embedlyLinkLoaded && !embedlyLinkError &&
loading...
} + {authorizedToEdit && ( +
+ )} +
+ ) } }