2020-03-23 20:24:17 +00:00
|
|
|
import React, { Component } from "react";
|
2020-03-25 16:20:53 +00:00
|
|
|
import { Menu, Grid, Icon, Responsive, Dropdown } from "semantic-ui-react";
|
2020-03-23 20:24:17 +00:00
|
|
|
import { editButtonStyle } from "../components/dashboard/devices/styleComponents";
|
2020-03-13 14:21:33 +00:00
|
|
|
import ModalWindow from "../components/modalform";
|
|
|
|
|
|
|
|
class Navbar extends Component {
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.state = {
|
2020-03-23 20:24:17 +00:00
|
|
|
activeItemName: "Home",
|
2020-03-22 16:58:27 +00:00
|
|
|
activeItem: -1,
|
2020-03-17 15:39:21 +00:00
|
|
|
edited: "",
|
2020-03-23 20:24:17 +00:00
|
|
|
editMode: false,
|
2020-03-25 21:15:52 +00:00
|
|
|
room: "",
|
2020-03-23 20:24:17 +00:00
|
|
|
};
|
2020-03-13 14:21:33 +00:00
|
|
|
}
|
|
|
|
|
2020-03-24 17:17:04 +00:00
|
|
|
componentDidMount() {
|
|
|
|
this.setState({
|
|
|
|
activeItem: this.props.activeItem,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-03-23 20:24:17 +00:00
|
|
|
editModeController = (e) =>
|
|
|
|
this.setState((prevState) => ({ editMode: !prevState.editMode }));
|
2020-03-13 14:21:33 +00:00
|
|
|
|
2020-03-23 20:24:17 +00:00
|
|
|
handleClick = (e, { id, name }) => {
|
2020-03-25 21:15:52 +00:00
|
|
|
const room = this.props.rooms.filter((d) => d.id === id)[0];
|
2020-03-25 23:15:02 +00:00
|
|
|
console.log(room);
|
2020-03-22 16:58:27 +00:00
|
|
|
this.setState({
|
2020-03-23 20:24:17 +00:00
|
|
|
activeItem: id,
|
|
|
|
activeItemName: name,
|
|
|
|
});
|
2020-03-25 23:15:02 +00:00
|
|
|
this.activeRoom = room;
|
|
|
|
console.log(this.activeRoom);
|
2020-03-25 21:15:52 +00:00
|
|
|
this.forceUpdate();
|
2020-03-23 20:24:17 +00:00
|
|
|
this.props.handleItemClick(id);
|
|
|
|
};
|
2020-03-13 14:21:33 +00:00
|
|
|
|
2020-03-23 20:24:17 +00:00
|
|
|
render() {
|
2020-03-13 14:21:33 +00:00
|
|
|
return (
|
2020-03-25 12:55:52 +00:00
|
|
|
<div style={{ background: "#1b1c1d!important", padding: "0 20px" }}>
|
|
|
|
<Responsive minWidth={768}>
|
|
|
|
<Grid>
|
|
|
|
<Grid.Row color="black">
|
|
|
|
<button style={editButtonStyle} onClick={this.editModeController}>
|
|
|
|
Edit
|
|
|
|
</button>
|
|
|
|
</Grid.Row>
|
|
|
|
<Grid.Row>
|
|
|
|
<Menu inverted fluid vertical>
|
|
|
|
<Menu.Item
|
|
|
|
key={-1}
|
|
|
|
id={-1}
|
|
|
|
name="Home"
|
|
|
|
active={this.state.activeItem === -1}
|
|
|
|
onClick={this.handleClick}
|
2020-03-23 20:24:17 +00:00
|
|
|
>
|
2020-03-25 12:55:52 +00:00
|
|
|
<Grid>
|
|
|
|
<Grid.Row>
|
|
|
|
<Grid.Column>
|
|
|
|
<Icon name="home" size="small" />
|
|
|
|
</Grid.Column>
|
|
|
|
<Grid.Column>HOME</Grid.Column>
|
|
|
|
</Grid.Row>
|
|
|
|
</Grid>
|
|
|
|
</Menu.Item>
|
2020-03-23 20:24:17 +00:00
|
|
|
|
2020-03-25 12:55:52 +00:00
|
|
|
{this.props.rooms
|
|
|
|
? this.props.rooms.map((e, i) => {
|
|
|
|
return (
|
|
|
|
<Menu.Item
|
|
|
|
id={e.id}
|
|
|
|
key={i}
|
|
|
|
name={e.name}
|
|
|
|
active={this.state.activeItem === e.id}
|
|
|
|
onClick={this.handleClick}
|
|
|
|
>
|
|
|
|
<Grid>
|
|
|
|
<Grid.Row>
|
|
|
|
<Grid.Column>
|
|
|
|
<Icon name={e.icon} size="small" />
|
|
|
|
</Grid.Column>
|
|
|
|
<Grid.Column width={8}>{e.name}</Grid.Column>
|
|
|
|
<Grid.Column floated="right">
|
|
|
|
{this.state.editMode ? (
|
|
|
|
<ModalWindow
|
|
|
|
type="modify"
|
|
|
|
idRoom={e}
|
|
|
|
updateRoom={this.props.updateRoom}
|
|
|
|
deleteRoom={this.props.deleteRoom}
|
|
|
|
/>
|
|
|
|
) : null}
|
|
|
|
</Grid.Column>
|
|
|
|
</Grid.Row>
|
|
|
|
</Grid>
|
|
|
|
</Menu.Item>
|
|
|
|
);
|
|
|
|
})
|
|
|
|
: null}
|
2020-03-13 14:21:33 +00:00
|
|
|
|
2020-03-25 12:55:52 +00:00
|
|
|
<Menu.Item
|
|
|
|
name="newM"
|
|
|
|
active={this.state.activeItem === "newM"}
|
|
|
|
>
|
|
|
|
<Grid>
|
|
|
|
<Grid.Row centered name="new">
|
|
|
|
<ModalWindow type="new" addRoom={this.props.addRoom} />
|
|
|
|
</Grid.Row>
|
|
|
|
</Grid>
|
|
|
|
</Menu.Item>
|
|
|
|
</Menu>
|
|
|
|
</Grid.Row>
|
|
|
|
</Grid>
|
|
|
|
</Responsive>
|
2020-03-23 20:24:17 +00:00
|
|
|
|
2020-03-25 12:55:52 +00:00
|
|
|
<Responsive maxWidth={768}>
|
|
|
|
<Menu>
|
|
|
|
<Dropdown item fluid text={this.state.activeItemName}>
|
|
|
|
<Dropdown.Menu>
|
|
|
|
<Dropdown.Item
|
|
|
|
key={-1}
|
|
|
|
id={-1}
|
|
|
|
name="Home"
|
|
|
|
active={this.state.activeItem === "Home"}
|
|
|
|
onClick={this.handleClick}
|
|
|
|
>
|
|
|
|
<Grid>
|
|
|
|
<Grid.Row>
|
|
|
|
<Grid.Column>
|
|
|
|
<Icon name="home" size="small" />
|
|
|
|
</Grid.Column>
|
|
|
|
<Grid.Column>Home</Grid.Column>
|
|
|
|
</Grid.Row>
|
|
|
|
</Grid>
|
|
|
|
</Dropdown.Item>
|
2020-03-23 20:24:17 +00:00
|
|
|
|
2020-03-25 12:55:52 +00:00
|
|
|
{this.props.rooms
|
|
|
|
? this.props.rooms.map((e, i) => {
|
|
|
|
return (
|
|
|
|
<Dropdown.Item
|
|
|
|
id={e.id}
|
|
|
|
key={i}
|
|
|
|
name={e.name}
|
|
|
|
active={this.state.activeItem === e.id}
|
|
|
|
onClick={this.handleClick}
|
|
|
|
>
|
|
|
|
<Grid>
|
|
|
|
<Grid.Row>
|
|
|
|
<Grid.Column width={1}>
|
|
|
|
<Icon name={e.icon} size="small" />
|
|
|
|
</Grid.Column>
|
|
|
|
<Grid.Column>{e.name}</Grid.Column>
|
|
|
|
</Grid.Row>
|
|
|
|
</Grid>
|
|
|
|
</Dropdown.Item>
|
|
|
|
);
|
|
|
|
})
|
|
|
|
: null}
|
|
|
|
</Dropdown.Menu>
|
|
|
|
</Dropdown>
|
|
|
|
</Menu>
|
|
|
|
<Grid inverted>
|
|
|
|
<Grid.Row>
|
|
|
|
<Grid.Column width={8}>
|
|
|
|
<ModalWindow type="new" addRoom={this.props.addRoom} />
|
|
|
|
</Grid.Column>
|
|
|
|
{this.state.activeItem !== -1 ? (
|
2020-03-23 20:24:17 +00:00
|
|
|
<Grid.Column width={8}>
|
2020-03-25 12:55:52 +00:00
|
|
|
<ModalWindow
|
|
|
|
type="modify"
|
2020-03-25 23:15:02 +00:00
|
|
|
idRoom={() => {
|
|
|
|
console.log("MALUSA", this.activeRoom);
|
|
|
|
return this.activeRoom;
|
|
|
|
}}
|
2020-03-25 12:55:52 +00:00
|
|
|
updateRoom={this.props.updateRoom}
|
|
|
|
deleteRoom={this.props.deleteRoom}
|
|
|
|
/>
|
2020-03-23 20:24:17 +00:00
|
|
|
</Grid.Column>
|
2020-03-25 12:55:52 +00:00
|
|
|
) : null}
|
|
|
|
</Grid.Row>
|
|
|
|
</Grid>
|
|
|
|
</Responsive>
|
2020-03-23 20:24:17 +00:00
|
|
|
</div>
|
2020-03-13 14:21:33 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default Navbar;
|