48 lines
1.1 KiB
JavaScript
48 lines
1.1 KiB
JavaScript
import React from 'react';
|
|
import {auth, baseURL} from './Meshify';
|
|
import {Company} from './Company';
|
|
import {isDefined} from './Utilities';
|
|
|
|
export class App extends React.Component {
|
|
constructor(props){
|
|
super(props);
|
|
this.state = {
|
|
companies: [],
|
|
loading: true
|
|
}
|
|
this.getData = this.getData.bind(this);
|
|
}
|
|
|
|
getData(){
|
|
fetch(baseURL + 'alldata', {credentials: 'include'}).then((response)=>response.json())
|
|
.then((responseJson)=>{
|
|
this.setState({companies: responseJson, loading: false});
|
|
})
|
|
}
|
|
|
|
componentDidMount() {
|
|
// this.getDeviceData();
|
|
this.getData()
|
|
}
|
|
|
|
|
|
render(){
|
|
const companyList = this.state.companies.map((company, id) => {
|
|
if(Object.keys(company.devices).length > 0){
|
|
return <Company companyObj={company} key={"company_" + id} />
|
|
}
|
|
})
|
|
|
|
const loading = <div style={{textAlign: "center", paddingTop: "25px"}}><h1>Loading...</h1></div>
|
|
|
|
const innerApp = this.state.loading ? loading : companyList
|
|
|
|
|
|
return (
|
|
<div id="innerApp">
|
|
{innerApp}
|
|
</div>
|
|
);
|
|
}
|
|
}
|