Skip to content

Commit

Permalink
modularized code
Browse files Browse the repository at this point in the history
  • Loading branch information
aquinojardim committed Aug 30, 2020
1 parent cf05529 commit acb1143
Show file tree
Hide file tree
Showing 17 changed files with 226 additions and 470 deletions.
16 changes: 2 additions & 14 deletions src/client/components/BottomBar.jsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,12 @@
/* eslint-disable react/prop-types */
import React from "react";
import { makeStyles } from "@material-ui/core/styles";
import { stylesBottomBar } from "../styles/stylesBottomBar";
import { BottomNavigation, BottomNavigationAction } from "@material-ui/core";
import SpeedIcon from "@material-ui/icons/Speed";
import EmojiObjectsIcon from "@material-ui/icons/EmojiObjects";

const useStyles = makeStyles({
root: {
width: "100%",
position: "fixed",
bottom: 0,
background: "black",
},
button: {
width: "100%",
},
});

export default function BottomBar({ view, setView }) {
const classes = useStyles();
const classes = stylesBottomBar();

return (
<BottomNavigation
Expand Down
16 changes: 2 additions & 14 deletions src/client/components/TopBar.jsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,11 @@
import React from "react";
import { makeStyles } from "@material-ui/core/styles";
import { stylesTopBar } from "../styles/stylesTopBar";
import { Toolbar, Typography, IconButton, MenuItem, Menu } from "@material-ui/core";
import MenuIcon from "@material-ui/icons/Menu";
import AccountCircle from "@material-ui/icons/AccountCircle";

const useStyles = makeStyles((theme) => ({
root: {
flexGrow: 1,
},
menuButton: {
marginRight: theme.spacing(2),
},
title: {
flexGrow: 1,
},
}));

export default function TopBar() {
const classes = useStyles();
const classes = stylesTopBar();
const [anchorEl, setAnchorEl] = React.useState(null);
const open = Boolean(anchorEl);
const today = new Date().toDateString();
Expand Down
62 changes: 7 additions & 55 deletions src/client/features/lights/LightPanel.jsx
Original file line number Diff line number Diff line change
@@ -1,72 +1,28 @@
import React from "react";
import * as actions from "../../reducer/actions/actions";
import { useSelector, useDispatch } from "react-redux";
import { makeStyles } from "@material-ui/core/styles";
import { stylesPanel } from "../../styles/stylesPanel";
import { Button, Drawer, List, Divider } from "@material-ui/core";
import PowerSettingsNewIcon from "@material-ui/icons/PowerSettingsNew";
import PowerOffIcon from "@material-ui/icons/PowerOff";
import LightItem from "./lightsComponents/LightItem";
import LightForm from "./lightsComponents/LightForm";

// custom styles for the drawer
const useStyles = makeStyles((theme) => ({
// drawer stays at fixed width, no matter the size of the screen
drawer: {
[theme.breakpoints.down("sm")]: {
width: "80%",
height: "80%",
margin: "10%",
},
[theme.breakpoints.up("md")]: {
width: "90%",
height: "80%",
margin: "5%",
},
flexShrink: 0,
},
button: {
width: "50%",
},
title: {
marginLeft: "18px",
marginTop: "52px",
},
// width of background of drawer
drawerPaper: {
backgroundColor: "#333",
[theme.breakpoints.up("xs")]: {
width: "80%",
height: "70%",
margin: "10%",
marginTop: "20%",
},
[theme.breakpoints.up("sm")]: {
width: "80%",
height: "80%",
margin: "10%",
},
[theme.breakpoints.up("md")]: {
width: "90%",
height: "80%",
margin: "5%",
},
},
drawerContainer: {
overflow: "auto",
},
}));


export default function LightPanel() {
// gives us access to styles object generated by makeStyles
const classes = useStyles();
const classes = stylesPanel();
// manupulated store central data
const dispatch = useDispatch();
// gives acess to store central data
const { lights } = useSelector((state) => state);
// reorganizes lights in an array
const lightsArray = Object.values(lights);

/* Drawer is our sidebar navigation component, stays permanently fixed to side, as docs recommend on desktop usage */

return (
<Drawer
// targets the nested component of the drawer (in this case, the paper)
classes={{
paper: classes.drawerPaper,
}}
Expand All @@ -76,7 +32,6 @@ export default function LightPanel() {
>
<h3 className={classes.title}> Lights Panel </h3>
<div className={classes.drawerContainer}>
{/* map topics to new navbar items (rendered as a list) */}
<Button
// eslint-disable-next-line no-unused-vars
onClick={(e) => {
Expand All @@ -100,8 +55,6 @@ export default function LightPanel() {
All Off
</Button>
<List>
{/* up and down implent logic comparing with Date.now()*/}
{/* <LightItem id={1} name={'test'} status={true}/> */}
{lightsArray.map((obj, index) => {
return (
<LightItem
Expand All @@ -113,7 +66,6 @@ export default function LightPanel() {
);
})}
<Divider />
{/* form to arr a new light */}
<LightForm />
</List>
</div>
Expand Down
11 changes: 2 additions & 9 deletions src/client/features/lights/lightsComponents/LightItem.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,12 @@
import React from "react";
import * as actions from "../../../reducer/actions/actions";
import { useDispatch } from "react-redux";
import { makeStyles } from "@material-ui/core/styles";
import { stylesLightItem } from "../lightsStyles/stylesLightItem";
import { FormControlLabel, ListItem, ListItemSecondaryAction, ListItemText, Switch, IconButton } from "@material-ui/core";
import DeleteIcon from "@material-ui/icons/Delete";

const useStyles = makeStyles(() => ({
name: {
position: "absolute",
left: "40%",
},
}));

export default function LightItem({ id, name, status }) {
const classes = useStyles();
const classes = stylesLightItem();
const dispatch = useDispatch();

const handleChange = (event) => {
Expand Down
10 changes: 10 additions & 0 deletions src/client/features/lights/lightsStyles/stylesLightItem.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { makeStyles } from "@material-ui/core/styles";

const stylesLightItem = makeStyles(() => ({
name: {
position: "absolute",
left: "40%",
},
}));

export { stylesLightItem }
47 changes: 4 additions & 43 deletions src/client/features/temperature/TemperaturePanel.jsx
Original file line number Diff line number Diff line change
@@ -1,65 +1,26 @@
import React from "react";
import * as actions from "../../reducer/actions/actions";
import { useSelector, useDispatch } from "react-redux";
import { makeStyles } from "@material-ui/core/styles";
import { stylesPanel } from "../../styles/stylesPanel";
import { green } from "@material-ui/core/colors";
import { Drawer, FormControlLabel, Switch } from "@material-ui/core";
import Thermostat from "./temperatureComponents/Thermostat";
import ChangeTemperature from "./temperatureComponents/ChangeTemperature";

// custom styles for the drawer
const useStyles = makeStyles((theme) => ({
// drawer stays at fixed width, no matter the size of the screen
drawer: {
flexShrink: 0,
},
title: {
marginLeft: "18px",
marginTop: "52px",
},
// width of background of drawer
drawerPaper: {
backgroundColor: "#333",
[theme.breakpoints.up("xs")]: {
width: "80%",
height: "70%",
margin: "10%",
marginTop: "20%",
},
[theme.breakpoints.up("sm")]: {
width: "80%",
height: "80%",
margin: "10%",
},
[theme.breakpoints.up("md")]: {
width: "90%",
height: "80%",
margin: "5%",
},
},
drawerContainer: {
overflow: "auto",
},
form: {
marginLeft: "auto",
marginRight: "auto",
},
}));

export default function TemperaturePanel() {
// gives us access to styles object generated by makeStyles
const classes = useStyles();
const classes = stylesPanel();
// gives acess to store central data
const { eco } = useSelector((state) => state);
// manupulated store central data
const dispatch = useDispatch();
// Set the initial state.

const handleChange = (event) => {
dispatch(actions.updateTemperature({ eco: event.target.checked }));
};

return (
<Drawer
// targets the nested component of the drawer (in this case, the paper)
classes={{
paper: classes.drawerPaper,
}}
Expand Down
Loading

0 comments on commit acb1143

Please sign in to comment.