import React, { Component } from "react"; import DevicePanel from "../components/dashboard/DevicePanel"; import ScenesPanel from "../components/dashboard/ScenesPanel"; import AutomationsPanel from "../components/dashboard/AutomationsPanel"; import HostsPanel from "../components/dashboard/HostsPanel"; import Navbar from "./Navbar"; import ScenesNavbar from "./ScenesNavbar"; import HostsNavbar from "./HostsNavbar"; import MyHeader from "../components/HeaderController"; import { Grid, Responsive, Button, Menu } from "semantic-ui-react"; import { panelStyle, mobilePanelStyle, } from "../components/dashboard/devices/styleComponents"; import { RemoteService } from "../remote"; import { connect } from "react-redux"; import { appActions } from "../storeActions"; class Dashboard extends Component { constructor(props) { super(props); this.state = this.initialState; this.activeTab = "Devices"; this.selectTab = this.selectTab.bind(this); } get initialState() { return { activeTab: this.activeTab, }; } setInitialState() { this.setState(this.initialState); } get activeTab() { return this.props.activeTab; } set activeTab(tab) { this.props.setActiveTab(tab); } selectTab(e, { name }) { this.setState({ activeTab: name }); this.activeTab = name; } renderTab(tab) { switch (tab) { case "Devices": return ; case "Scenes": return ; case "Automations": return ; case "Hosts": return ; default: return

ERROR

; } } renderNavbar(tab) { switch (tab) { case "Devices": return ; case "Scenes": return ; case "Hosts": return ; default: return

ERROR

; } } get hasNavbar() { return this.state.activeTab !== "Automations"; } render() { // needed to correctly assign the background image //in case a room has one. let backgroundImageHelper; if(this.activeTab==="Devices"){ backgroundImageHelper=this.props.allRooms; }else{ backgroundImageHelper=null; } //console.log("helper is",helper) return (
{this.hasNavbar && ( {this.renderNavbar(this.activeTab)} )}
{this.renderTab(this.activeTab)}
); } } const mapStateToProps = (state, _) => ({ activeTab: state.active.activeTab, get currentRoom(){ return state.active.activeRoom; }, //this took me way longer to figure out than it should have get allRooms(){ if(state.active.activeRoom==-1){ return null; } for(let i in state.rooms){ if(i==state.active.activeRoom){ //console.log("check",state.rooms[i].image) if(state.rooms[i].image===undefined){ return null; }else{ return state.rooms[i].image; } } } }, }); const setActiveTab = (activeTab) => { return (dispatch) => dispatch(appActions.setActiveTab(activeTab)); }; const DashboardContainer = connect(mapStateToProps, { ...RemoteService, setActiveTab, })(Dashboard); export default DashboardContainer;