-
Notifications
You must be signed in to change notification settings - Fork 8
/
SampleList.js
43 lines (34 loc) · 1.15 KB
/
SampleList.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import {API_URL_SAMPLES} from '../config'
import React, { Component } from 'react'
import axios from 'axios'
class SampleList extends Component {
constructor(props){
super(props);
this.state = {
onSelect: props.onSelect,
options: []
}
}
get_samples() {
axios.get(`${API_URL_SAMPLES}`)
.then(({ data }) => {
this.setState({
options: [<option value='' key="no-selection">Please select...</option>]
.concat(data.map(r => (
<option value={r.file} key={r.file}>{r.title}</option>
)))
})
})
.catch(() => this.setState({ error: true }))
}
componentDidMount() {
this.get_samples()
}
select = (event) => {
this.state.onSelect(event.target.value)
}
render() {
return <select className='form-control' onChange={this.select}>{this.state.options}</select>
}
}
export default SampleList