import React, { Component } from 'react'; import { Grid, Responsive, Button, Menu, } from 'semantic-ui-react'; import { connect } from 'react-redux'; 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 { mobilePanelStyle } from '../components/dashboard/devices/styleComponents'; import { RemoteService } from '../remote'; 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.backgroundImage; } 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; }, get backgroundImage() { if (state.active.activeRoom === -1) { return null; } return state.rooms[state.active.activeRoom].image; }, }); const setActiveTab = (activeTab) => (dispatch) => dispatch(appActions.setActiveTab(activeTab)); const DashboardContainer = connect(mapStateToProps, { ...RemoteService, setActiveTab, })(Dashboard); export default DashboardContainer;