2021-02-26 20:50:08 +00:00
|
|
|
import React from "react";
|
2021-02-27 10:56:38 +00:00
|
|
|
import Dropdown from "react-dropdown";
|
|
|
|
import "react-dropdown/style.css";
|
2021-02-26 20:50:08 +00:00
|
|
|
|
|
|
|
var values;
|
2021-02-27 10:56:38 +00:00
|
|
|
let arr = [];
|
2021-02-26 20:50:08 +00:00
|
|
|
class DropDown extends React.Component {
|
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
this.state = {
|
|
|
|
options: [],
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
this.fetchOptions();
|
|
|
|
}
|
|
|
|
|
|
|
|
fetchOptions() {
|
|
|
|
fetch("/getStreamNames")
|
|
|
|
.then((res) => {
|
|
|
|
return res.json();
|
|
|
|
})
|
|
|
|
.then((json) => {
|
|
|
|
values = json;
|
2021-02-27 10:56:38 +00:00
|
|
|
|
2021-02-26 20:50:08 +00:00
|
|
|
values.forEach((element) => {
|
|
|
|
arr.push(element.streamName);
|
|
|
|
});
|
|
|
|
this.setState({ options: arr });
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
handleChange = (event) => {
|
|
|
|
this.setState({
|
2021-02-27 10:56:38 +00:00
|
|
|
value: event.target.value,
|
2021-02-26 20:50:08 +00:00
|
|
|
});
|
2021-02-27 10:56:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
_onSelect = (e) => {
|
|
|
|
/*
|
|
|
|
Because we named the inputs to match their
|
|
|
|
corresponding values in state, it's
|
|
|
|
super easy to update the state
|
|
|
|
*/
|
|
|
|
this.setState({ stream: e.value });
|
|
|
|
};
|
|
|
|
|
|
|
|
onChange = (e) => {
|
|
|
|
/*
|
|
|
|
Because we named the inputs to match their
|
|
|
|
corresponding values in state, it's
|
|
|
|
super easy to update the state
|
|
|
|
*/
|
|
|
|
this.setState({ [e.target.name]: e.target.value });
|
|
|
|
};
|
2021-02-26 20:50:08 +00:00
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
2021-02-27 10:56:38 +00:00
|
|
|
<Dropdown
|
|
|
|
options={arr}
|
|
|
|
onChange={this._onSelect}
|
|
|
|
value={arr[0]}
|
|
|
|
placeholder="Select an option"
|
|
|
|
/>
|
2021-02-26 20:50:08 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default DropDown;
|