fix embedly

This commit is contained in:
Devin Howard 2017-01-28 16:21:33 -05:00
parent 4eab4cefe8
commit 9f29a24321

View file

@ -61,7 +61,7 @@ class Attachments extends Component {
loadLink = () => { loadLink = () => {
this.setState({embedlyLinkStarted: true}) this.setState({embedlyLinkStarted: true})
var e = embedly('card', document.getElementById('embedlyLink')) 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 = () => { removeLink = () => {
@ -76,24 +76,21 @@ class Attachments extends Component {
render = () => { render = () => {
const { topic, ActiveMapper } = this.props const { topic, ActiveMapper } = this.props
const { linkEdit, embedlyLinkLoaded, embedlyLinkStarted, embedlyLinkError } = this.state 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') !== '' const hasAttachment = topic.get('link') && topic.get('link') !== ''
if (hasAttachment) { if (!hasAttachment && !authorizedToEdit) return null
const className = hasAttachment
? `embeds ${embedlyLinkLoaded ? '' : 'nonEmbedlyLink'}`
: 'attachments'
return ( return (
<div className={`embeds ${embedlyLinkLoaded ? '' : 'nonEmbedlyLink'}`}> <div className={className}>
<a href={topic.get('link')} id="embedlyLink" target="_blank" data-card-description="0"> <div className="addLink"
{topic.get('link')} style={{ display: hasAttachment ? 'none' : 'block' }}
</a> >
{embedlyLinkStarted && !embedlyLinkLoaded && !embedlyLinkError && <div id="embedlyLinkLoader">loading...</div>}
{authorizedToEdit && <div id="linkremove" onClick={this.removeLink}></div>}
</div>
)
} else if (authorizedToEdit) {
return (
<div className="attachments">
<div className="addLink">
<div id="addLinkIcon"></div> <div id="addLinkIcon"></div>
<div id="addLinkInput"> <div id="addLinkInput">
<input ref={input => this.linkInput = input} <input ref={input => this.linkInput = input}
@ -104,11 +101,23 @@ class Attachments extends Component {
{linkEdit && <div id="addLinkReset"></div>} {linkEdit && <div id="addLinkReset"></div>}
</div> </div>
</div> </div>
<a style={{ display: hasAttachment ? 'block' : 'none' }}
href={topic.get('link')}
id="embedlyLink"
target="_blank"
data-card-description="0"
>
{topic.get('link')}
</a>
{embedlyLinkStarted && !embedlyLinkLoaded && !embedlyLinkError && <div id="embedlyLinkLoader">loading...</div>}
{authorizedToEdit && (
<div id="linkremove"
style={{ display: hasAttachment ? 'block' : 'none' }}
onClick={this.removeLink}
/>
)}
</div> </div>
) )
} else {
return null
}
} }
} }