Basic Tabs system
This commit is contained in:
parent
2976ed7dc3
commit
82c4f3ea57
7 changed files with 154 additions and 19 deletions
23
smart-hut/src/components/dashboard/AutomationsPanel.js
Normal file
23
smart-hut/src/components/dashboard/AutomationsPanel.js
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
import React, { Component } from "react";
|
||||||
|
import { connect } from "react-redux";
|
||||||
|
import { RemoteService } from "../../remote";
|
||||||
|
|
||||||
|
class AutomationsPanel extends Component {
|
||||||
|
constructor(props) {
|
||||||
|
super(props);
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
return <h1 color="black">AUTOMATIONS</h1>;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const mapStateToProps = (state, _) => ({
|
||||||
|
activeRoom: state.active.activeRoom,
|
||||||
|
activeTab: state.active.activeTab,
|
||||||
|
});
|
||||||
|
const AutomationsPanelContainer = connect(
|
||||||
|
mapStateToProps,
|
||||||
|
RemoteService
|
||||||
|
)(AutomationsPanel);
|
||||||
|
export default AutomationsPanelContainer;
|
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
import React, { Component } from "react";
|
import React, { Component } from "react";
|
||||||
import { Grid } from "semantic-ui-react";
|
import { Grid } from "semantic-ui-react";
|
||||||
import { panelStyle } from "./devices/styleComponents";
|
|
||||||
import Device from "./devices/Device";
|
import Device from "./devices/Device";
|
||||||
import NewDevice from "./devices/NewDevice";
|
import NewDevice from "./devices/NewDevice";
|
||||||
import { connect } from "react-redux";
|
import { connect } from "react-redux";
|
||||||
|
@ -23,22 +22,20 @@ class DevicePanel extends Component {
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<div style={panelStyle}>
|
<Grid doubling columns={2} divided="vertically">
|
||||||
<Grid doubling columns={2} divided="vertically">
|
{this.props.devices.map((e, i) => {
|
||||||
{this.props.devices.map((e, i) => {
|
return (
|
||||||
return (
|
<Grid.Column key={i}>
|
||||||
<Grid.Column key={i}>
|
<Device id={e.id} />
|
||||||
<Device id={e.id} />
|
|
||||||
</Grid.Column>
|
|
||||||
);
|
|
||||||
})}
|
|
||||||
{!this.props.isActiveRoomHome ? (
|
|
||||||
<Grid.Column>
|
|
||||||
<NewDevice />
|
|
||||||
</Grid.Column>
|
</Grid.Column>
|
||||||
) : null}
|
);
|
||||||
</Grid>
|
})}
|
||||||
</div>
|
{!this.props.isActiveRoomHome ? (
|
||||||
|
<Grid.Column>
|
||||||
|
<NewDevice />
|
||||||
|
</Grid.Column>
|
||||||
|
) : null}
|
||||||
|
</Grid>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
23
smart-hut/src/components/dashboard/ScenesPanel.js
Normal file
23
smart-hut/src/components/dashboard/ScenesPanel.js
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
import React, { Component } from "react";
|
||||||
|
import { connect } from "react-redux";
|
||||||
|
import { RemoteService } from "../../remote";
|
||||||
|
|
||||||
|
class ScenesPanel extends Component {
|
||||||
|
constructor(props) {
|
||||||
|
super(props);
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
return <h1 color="black">SCENES</h1>;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const mapStateToProps = (state, _) => ({
|
||||||
|
activeRoom: state.active.activeRoom,
|
||||||
|
activeTab: state.active.activeTab,
|
||||||
|
});
|
||||||
|
const ScenesPanelContainer = connect(
|
||||||
|
mapStateToProps,
|
||||||
|
RemoteService
|
||||||
|
)(ScenesPanel);
|
||||||
|
export default ScenesPanelContainer;
|
|
@ -23,6 +23,7 @@ export const panelStyle = {
|
||||||
height: "100vh",
|
height: "100vh",
|
||||||
width: "auto",
|
width: "auto",
|
||||||
padding: "0rem 3rem",
|
padding: "0rem 3rem",
|
||||||
|
color: "#000000",
|
||||||
};
|
};
|
||||||
|
|
||||||
export const editModeStyle = {
|
export const editModeStyle = {
|
||||||
|
|
|
@ -231,6 +231,15 @@ function reducer(previousState, action) {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
case "SET_ACTIVE_TAB":
|
||||||
|
newState = update(previousState, {
|
||||||
|
active: {
|
||||||
|
activeTab: {
|
||||||
|
$set: action.activeTab,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
break;
|
||||||
case "REDUX_WEBSOCKET::MESSAGE":
|
case "REDUX_WEBSOCKET::MESSAGE":
|
||||||
const devices = JSON.parse(action.payload.message);
|
const devices = JSON.parse(action.payload.message);
|
||||||
console.log(devices);
|
console.log(devices);
|
||||||
|
@ -255,6 +264,7 @@ const initState = {
|
||||||
},
|
},
|
||||||
active: {
|
active: {
|
||||||
activeRoom: -1,
|
activeRoom: -1,
|
||||||
|
activeTab: "Devices",
|
||||||
},
|
},
|
||||||
login: {
|
login: {
|
||||||
loggedIn: false,
|
loggedIn: false,
|
||||||
|
|
|
@ -52,6 +52,10 @@ export const appActions = {
|
||||||
type: "SET_ACTIVE_ROOM",
|
type: "SET_ACTIVE_ROOM",
|
||||||
activeRoom,
|
activeRoom,
|
||||||
}),
|
}),
|
||||||
|
setActiveTab: (activeTab) => ({
|
||||||
|
type: "SET_ACTIVE_TAB",
|
||||||
|
activeTab,
|
||||||
|
}),
|
||||||
};
|
};
|
||||||
|
|
||||||
export default actions;
|
export default actions;
|
||||||
|
|
|
@ -1,10 +1,48 @@
|
||||||
import React, { Component } from "react";
|
import React, { Component } from "react";
|
||||||
import DevicePanel from "../components/dashboard/DevicePanel";
|
import DevicePanel from "../components/dashboard/DevicePanel";
|
||||||
|
import ScenesPanel from "../components/dashboard/ScenesPanel";
|
||||||
|
import AutomationsPanel from "../components/dashboard/AutomationsPanel";
|
||||||
import Navbar from "./Navbar";
|
import Navbar from "./Navbar";
|
||||||
import MyHeader from "../components/HeaderController";
|
import MyHeader from "../components/HeaderController";
|
||||||
import { Grid, Responsive } from "semantic-ui-react";
|
import { Grid, Responsive, Button } from "semantic-ui-react";
|
||||||
|
import { panelStyle } 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.selectTab = this.selectTab.bind(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
get activeTab() {
|
||||||
|
return this.props.activeTab;
|
||||||
|
}
|
||||||
|
|
||||||
|
set activeTab(tab) {
|
||||||
|
this.props.setActiveTab(tab);
|
||||||
|
}
|
||||||
|
|
||||||
|
selectTab(e, { name }) {
|
||||||
|
this.activeTab = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
renderTab(tab) {
|
||||||
|
switch (tab) {
|
||||||
|
case "Devices":
|
||||||
|
return <DevicePanel />;
|
||||||
|
case "Scenes":
|
||||||
|
return <ScenesPanel />;
|
||||||
|
case "Automations":
|
||||||
|
return <AutomationsPanel />;
|
||||||
|
default:
|
||||||
|
return <h1>ERROR</h1>;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export default class Dashboard extends Component {
|
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<div style={{ height: "110vh", background: "#1b1c1d" }}>
|
<div style={{ height: "110vh", background: "#1b1c1d" }}>
|
||||||
|
@ -15,13 +53,38 @@ export default class Dashboard extends Component {
|
||||||
<MyHeader />
|
<MyHeader />
|
||||||
</Grid.Column>
|
</Grid.Column>
|
||||||
</Grid.Row>
|
</Grid.Row>
|
||||||
|
<Grid.Row color="black" centered>
|
||||||
|
<Grid.Column>
|
||||||
|
<Button
|
||||||
|
name="Devices"
|
||||||
|
content="Devices"
|
||||||
|
active={this.activeTab === "Devices"}
|
||||||
|
color={this.activeTab === "Devices" ? "green" : "olive"}
|
||||||
|
onClick={this.selectTab}
|
||||||
|
/>
|
||||||
|
<Button
|
||||||
|
name="Scenes"
|
||||||
|
content="Scenes"
|
||||||
|
active={this.activeTab === "Scenes"}
|
||||||
|
color={this.activeTab === "Scenes" ? "green" : "olive"}
|
||||||
|
onClick={this.selectTab}
|
||||||
|
/>
|
||||||
|
<Button
|
||||||
|
name="Automations"
|
||||||
|
content="Automations"
|
||||||
|
active={this.activeTab === "Automations"}
|
||||||
|
color={this.activeTab === "Automations" ? "green" : "olive"}
|
||||||
|
onClick={this.selectTab}
|
||||||
|
/>
|
||||||
|
</Grid.Column>
|
||||||
|
</Grid.Row>
|
||||||
<Grid.Row color="black">
|
<Grid.Row color="black">
|
||||||
<Grid.Column width={3}>
|
<Grid.Column width={3}>
|
||||||
<Navbar />
|
<Navbar />
|
||||||
</Grid.Column>
|
</Grid.Column>
|
||||||
|
|
||||||
<Grid.Column width={13}>
|
<Grid.Column width={13}>
|
||||||
<DevicePanel />
|
<div style={panelStyle}>{this.renderTab(this.activeTab)}</div>
|
||||||
</Grid.Column>
|
</Grid.Column>
|
||||||
</Grid.Row>
|
</Grid.Row>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
@ -49,3 +112,17 @@ export default class Dashboard extends Component {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const mapStateToProps = (state, _) => ({
|
||||||
|
activeTab: state.active.activeTab,
|
||||||
|
});
|
||||||
|
|
||||||
|
const setActiveTab = (activeTab) => {
|
||||||
|
return (dispatch) => dispatch(appActions.setActiveTab(activeTab));
|
||||||
|
};
|
||||||
|
|
||||||
|
const DashboardContainer = connect(mapStateToProps, {
|
||||||
|
...RemoteService,
|
||||||
|
setActiveTab,
|
||||||
|
})(Dashboard);
|
||||||
|
export default DashboardContainer;
|
||||||
|
|
Loading…
Reference in a new issue