frontend/smart-hut/src/views/Dashboard.js

82 lines
2.0 KiB
JavaScript
Raw Normal View History

2020-03-11 16:38:04 +00:00
import React, {Component} from 'react';
import DevicePanel from "../components/dashboard/DevicePanel";
2020-03-13 14:12:28 +00:00
import NavbarTest from './NavbarTest'
import MyHeader from '../components/HeaderController'
2020-03-11 16:38:04 +00:00
import { call } from '../client_server';
import {Button} from 'semantic-ui-react';
import { Menu } from 'semantic-ui-react'
import { Grid, Image, Icon } from 'semantic-ui-react'
2020-03-13 14:12:28 +00:00
2020-03-11 16:38:04 +00:00
export default class Dashboard extends Component{
constructor(props) {
super(props);
this.state = {
rooms: [],
activeItem: "Home"
};
this.addRoom = this.addRoom.bind(this);
this.handleItemClick = this.handleItemClick.bind(this);
}
2020-03-13 14:12:28 +00:00
componentDidMount() {
2020-03-11 16:38:04 +00:00
call.getAllRooms(this.props.token)
.then(res => {
res.data.forEach((e) => {
this.setState(state => ({
rooms: state.rooms.concat([e])
}));
});
console.log(res, this.state.rooms)
}).catch(err => {
console.log(err);
});
}
addRoom(e) {
e.preventDefault();
const params = {
"icon": "ciao",
"image": "ciao",
"name": "kitchen"
}
call.createRoom(params)
.then(res => {
console.log(res);
if (res.status === 200 && res.data) {
this.setState(state => ({
rooms: state.rooms.concat([res.data])
}));
}
console.log(this.state.rooms);
}).catch(err => {
console.log(err);
});
};
handleItemClick(el) {
//da fare richiesta get della room e settare activeItem
}
render () {
return(
2020-03-13 14:12:28 +00:00
<div style={{height : "110vh", background: '#1b1c1d'}}>
<MyHeader />
<Grid >
<Grid.Row color='black'>
2020-03-11 16:38:04 +00:00
<Grid.Column width={3}>
2020-03-13 14:12:28 +00:00
<NavbarTest addRoom={this.addRoom} rooms={this.state.rooms} handleItemClick={this.handleItemClick}/>
2020-03-11 16:38:04 +00:00
</Grid.Column>
<Grid.Column width={13}>
<DevicePanel />
2020-03-13 14:12:28 +00:00
</Grid.Column>
2020-03-11 16:38:04 +00:00
</Grid.Row>
</Grid>
</div>
)
}
}