diff --git a/packages/vulcan-embed/lib/components/EmbedURL.jsx b/packages/vulcan-embed/lib/components/EmbedURL.jsx index 23c81f6af..fbfb195bc 100644 --- a/packages/vulcan-embed/lib/components/EmbedURL.jsx +++ b/packages/vulcan-embed/lib/components/EmbedURL.jsx @@ -3,7 +3,6 @@ import { withMutation } from 'meteor/vulcan:core'; import React, { Component } from 'react'; import PropTypes from 'prop-types'; import { FormattedMessage, intlShape } from 'meteor/vulcan:i18n'; -import Form from 'react-bootstrap/Form'; class EmbedURL extends Component { constructor(props) { @@ -43,10 +42,9 @@ class EmbedURL extends Component { }; // called whenever the URL input field loses focus - handleBlur = async () => { + handleBlur = async e => { try { - // value from formsy input ref - const url = this.input.getValue(); + const url = e.target.value; // start the mutation only if the input has a value if (url.length) { @@ -60,7 +58,11 @@ class EmbedURL extends Component { // console.log('Embedly Data', result); // extract the relevant data, for easier consumption - const { data: { getEmbedData: { title, description, thumbnailUrl } } } = result; + const { + data: { + getEmbedData: { title, description, thumbnailUrl }, + }, + } = result; const body = description; // update the form @@ -91,7 +93,10 @@ class EmbedURL extends Component { this.setState({ loading: false }); // something bad happened - this.context.throwError({ id: 'embedurl.error_fetching_data', data: { name: this.props.path, message: errorMessage } }); + this.context.throwError({ + id: 'embedurl.error_fetching_data', + data: { name: this.props.path, message: errorMessage }, + }); } }; @@ -106,10 +111,26 @@ class EmbedURL extends Component { }; }; + getLoadingStyle = () => { + const loadingStyle = { + display: this.state.loading ? 'block' : 'none' + }; + + return loadingStyle; + }; + renderThumbnail() { return (
- + + +
+ +
@@ -128,11 +149,14 @@ class EmbedURL extends Component {
+ className="embedly-thumbnail-placeholder">
+ +
+ +
); } @@ -142,38 +166,29 @@ class EmbedURL extends Component { position: 'relative', }; - const loadingStyle = { - position: 'absolute', - pointerEvents: 'none', - top: '15px', - right: '15px', - }; - - loadingStyle.display = this.state.loading ? 'block' : 'none'; - // see https://facebook.github.io/react/warnings/unknown-prop.html const { document, control, getEmbedData, refFunction, inputProperties } = this.props; // eslint-disable-line return ( -
- -
-
- (this.input = ref)} - layout="elementOnly" - /> -
- + + {this.context.getDocument().thumbnailUrl + ? this.renderThumbnail() + : this.renderNoThumbnail()}
-
- - {this.context.getDocument().thumbnailUrl ? this.renderThumbnail() : this.renderNoThumbnail()} -
-
+ ), + }} + /> ); } } diff --git a/packages/vulcan-embed/lib/stylesheets/embedly.scss b/packages/vulcan-embed/lib/stylesheets/embedly.scss index 3b1ed68a9..ef8cccfd6 100644 --- a/packages/vulcan-embed/lib/stylesheets/embedly.scss +++ b/packages/vulcan-embed/lib/stylesheets/embedly.scss @@ -8,6 +8,18 @@ margin-right: 10px; } +.form-component-EmbedURL{ + .col-sm-9{ + display: flex; + } + input{ + margin-right: 10px; + } +} + +.embedly-thumbnail{ + position: relative; +} .embedly-thumbnail-placeholder{ background: #eee; display: flex; @@ -43,4 +55,13 @@ span{ display: none; } +} + +.embedly-url-field-loading{ + position: absolute; + pointer-events: none; + top: 50%; + left: 50%; + margin-top: -5px; + margin-left: -20px; } \ No newline at end of file