import React from 'react';
import PropTypes from 'prop-types';
import { Modal, FormControl, Col, Form, FormGroup, ControlLabel, Button } from 'react-bootstrap';
import Ediphy from '../../../../../../core/editor/main';
import i18n from 'i18next';
import ReactDOM from 'react-dom';
import SearchComponent from '../common/SearchComponent';
import placeholder from '../logos/soundcloud_placeholder.png';
export default class SoundCloudComponent extends React.Component {
constructor(props) {
super(props);
this.state = {
results: [],
query: '',
msg: 'No hay resultados',
};
this.onSearch = this.onSearch.bind(this);
}
render() {
return
;
}
onSearch(text) {
const BASE = 'https://api.audioblocks.com/api/search?srch-term=' + encodeURI(text) + '&srch-type=music&callback=?';
this.setState({ msg: 'Buscando...' });
fetch((BASE), {
jsonpCallback: '1',
mode: 'no-cors',
json: true,
})
.then(res => { return res.json();}
).then(audioStr => {
let songs = (audioStr);
if (songs) {
let results = Object.keys(songs.data.stockItems).map(a=>{
let s = songs.data.stockItems[a].stockItem;
return { title: s.title, url: s.previewUrl, thumbnail: s.thumbnailUrl };
});
this.setState({ results, msg: results.length > 0 ? '' : 'No hay resultados' });
}
}).catch(e=>{
// eslint-disable-next-line no-console
console.error(e);
this.setState({ msg: 'Ha habido un error' });
});
/* $.ajax(BASE, (result)=>{
try{
} catch (e) {
console.error(e);
this.setState({ msg: 'Ha habido un error' });
}
});*/
}
}
SoundCloudComponent.propTypes = {
/**
* Selected Element
*/
elementSelected: PropTypes.any,
/**
* Select element callback
*/
onElementSelected: PropTypes.func.isRequired,
/**
* Icon that identifies the API provider
*/
icon: PropTypes.any,
/**
* API Provider name
*/
name: PropTypes.string,
};