diff --git a/src/app/components/editor.js b/src/app/components/editor.js index 170d79a6..e101413a 100644 --- a/src/app/components/editor.js +++ b/src/app/components/editor.js @@ -68,6 +68,7 @@ class Index extends Component { lastGen: null, yamlLoaded: false }; + this.onLoadingRemote = this.props.onLoadingRemote.bind(this); } initBootstrap() { @@ -397,6 +398,7 @@ class Index extends Component { loading, values, allFields, + onLoadingRemote: this.onLoadingRemote, onLoad: this.parseYml.bind(this), onReset: this.reset.bind(this) }; diff --git a/src/app/components/sidebar.js b/src/app/components/sidebar.js index 5b40434b..7911ae5c 100644 --- a/src/app/components/sidebar.js +++ b/src/app/components/sidebar.js @@ -11,7 +11,7 @@ import img_download from "../../asset/img/download.svg"; import img_dots from "../../asset/img/dots.svg"; import img_xx from "../../asset/img/xx.svg"; -import { getRemoteYml } from "../utils/calls"; +import { getRemoteYml, passRemoteURLToValidator } from "../utils/calls"; import { getLabel } from "../contents/data"; function mapStateToProps(state) { @@ -65,9 +65,24 @@ class sidebar extends Component { let yaml = null; try { - yaml = await getRemoteYml(remoteYml); + this.setState({ loading: true }); + this.props.onLoadingRemote(true); + + // trying to get file and process it, cors problem + // yaml = await getRemoteYml(remoteYml); + + // piping url to validator which will returns a fresh + // and validated copy + yaml = await passRemoteURLToValidator(remoteYml); + onLoad(yaml); + + this.setState({ loading: false }); + this.props.onLoadingRemote(false); } catch (error) { + + this.setState({ loading: false }); + this.props.onLoadingRemote(false); console.error(error); alert("error parsing remote yaml"); } @@ -92,7 +107,7 @@ class sidebar extends Component { onReset(); - reader.onload = function() { + reader.onload = function () { let yaml = reader.result; onLoad(yaml); document.getElementById("load_yaml").value = ""; @@ -103,9 +118,9 @@ class sidebar extends Component { download(data) { //has dom - if (!data || data.length == 0){ - return; - } + if (!data || data.length == 0) { + return; + } const blob = new Blob([data], { type: "text/yaml;charset=utf-8;" }); @@ -117,7 +132,7 @@ class sidebar extends Component { tempLink.setAttribute("download", "publiccode.yml"); document.body.appendChild(tempLink); tempLink.click(); - setTimeout(function() { + setTimeout(function () { document.body.removeChild(tempLink); window.URL.revokeObjectURL(blobURL); }, 1000); @@ -199,7 +214,7 @@ class sidebar extends Component { -