54 lines
1.4 KiB
JavaScript
54 lines
1.4 KiB
JavaScript
import React from 'react';
|
|
import {auth, baseURL, channelStarter} from './Meshify';
|
|
import {Device} from './Device';
|
|
|
|
export class DeviceList extends React.Component {
|
|
constructor(props){
|
|
super(props);
|
|
this.state = {
|
|
tableVisible: true
|
|
}
|
|
this.toggleTable = this.toggleTable.bind(this)
|
|
}
|
|
|
|
toggleTable(){
|
|
this.setState({tableVisible: !this.state.tableVisible});
|
|
}
|
|
|
|
|
|
render(){
|
|
const devices = this.props.deviceList.map((dev, i) =>{
|
|
return (
|
|
<Device key={this.props.deviceType + "_" + i}
|
|
deviceId={dev.id}
|
|
deviceType={this.props.listName}
|
|
name={dev.vanityName}
|
|
values={dev.values}
|
|
channelStarter={channelStarter[this.props.deviceType]} />
|
|
);
|
|
});
|
|
|
|
let showHideButton
|
|
let deviceTable
|
|
if (this.state.tableVisible){
|
|
showHideButton = <button className="btn btn-outline-primary" onClick={this.toggleTable}>Hide</button>;
|
|
deviceTable = <table className="table small table-bordered table-responsive">
|
|
{this.props.tableHead}
|
|
<tbody>
|
|
{devices}
|
|
</tbody>
|
|
</table>
|
|
} else {
|
|
showHideButton = <button className="btn btn-outline-primary" onClick={this.toggleTable}>Show</button>;
|
|
deviceTable = <span></span>
|
|
}
|
|
|
|
return (
|
|
<div className="container-fluid">
|
|
<h2>{this.props.listName}[{devices.length}] {showHideButton}</h2>
|
|
{deviceTable}
|
|
</div>
|
|
)
|
|
}
|
|
}
|