diff --git a/src/components/AppView/AppView.js b/src/components/AppView/AppView.js index abb7e67..b0aa023 100644 --- a/src/components/AppView/AppView.js +++ b/src/components/AppView/AppView.js @@ -9,8 +9,11 @@ import ItemViewAppBar from "../ItemViewAppBar/"; import ItemView from "../ItemView/"; import QueueSelector from "../QueueSelector/"; import { useToken } from "../AuthProvider/"; +import ItemAppBar from "../ItemAppBar"; +import DarkModeIcon from '@material-ui/icons/Brightness4'; +import LightModeIcon from '@material-ui/icons/Brightness7'; -export default function AppView({ setDarkMode }){ +export default function AppView({ setDarkMode }) { // Create stateful variables. const [sidebarOpen, setSidebarOpen] = useState(false); const [queues, setQueues] = useState([]); @@ -22,17 +25,17 @@ export default function AppView({ setDarkMode }){ const access_token = useToken(); // Get Queues from API. - useEffect( _ => { - (async function getQueues(){ - if (access_token === null){ + useEffect(_ => { + (async function getQueues() { + if (access_token === null) { return undefined; } - if (queueSelectorOpen){ + if (queueSelectorOpen) { return undefined; } - if (selectedQueues.length === 0){ + if (selectedQueues.length === 0) { setQueues([]) return undefined; } @@ -40,16 +43,16 @@ export default function AppView({ setDarkMode }){ setIsLoading(true); let queuesToLoad = ""; - if (selectedQueues.length === 1){ + if (selectedQueues.length === 1) { queuesToLoad = selectedQueues[0].name; } - else if (selectedQueues.length > 0){ - selectedQueues.forEach( (queue, index) => ( + else if (selectedQueues.length > 0) { + selectedQueues.forEach((queue, index) => ( index === 0 ? queuesToLoad += queue.name : queuesToLoad += `+${queue.name}` )); - } + } let myHeaders = new Headers(); myHeaders.append("Authorization", `Bearer ${access_token}`); @@ -64,9 +67,9 @@ export default function AppView({ setDarkMode }){ }, [selectedQueues, access_token, queueSelectorOpen]); // Populate items array. - useEffect( _ => { + useEffect(_ => { let tempItems = []; - for (let queue of queues){ + for (let queue of queues) { tempItems = tempItems.concat(queue.items); } setItems(tempItems); @@ -103,19 +106,23 @@ export default function AppView({ setDarkMode }){ } }, }); + + const darkMode = theme.palette.type === "dark" + const toggleDarkMode = () => setDarkMode(!darkMode); + const classes = useStyles(); - return( + return ( - - + - + {items.length === 0 ? null : @@ -123,13 +130,13 @@ export default function AppView({ setDarkMode }){ path="/:queue/:number" render={({ match }) => ( <> - - )} diff --git a/src/components/ItemAppBar/ItemAppBar.js b/src/components/ItemAppBar/ItemAppBar.js new file mode 100644 index 0000000..6d157c4 --- /dev/null +++ b/src/components/ItemAppBar/ItemAppBar.js @@ -0,0 +1,33 @@ +import React from "react"; +import PropTypes from 'prop-types'; +import { AppBar } from "@material-ui/core" +import ItemTableAppBarActions from "../ItemAppBarActions/ItemAppBarActions"; + +export default function ItemAppBar({ title, tooltipTitle, onClick, icon, color }) { + + return ( + + + + ); +}; + +ItemAppBar.propTypes = { + /** The title of the app bar. */ + "title": PropTypes.string, + /** The tooltip that appears when the icon is hovered over. */ + "toolbarTitle": PropTypes.string, + /** The function that is is ran when icon button is clicked */ + "onClick": PropTypes.func.isRequired, + /** The title of the app bar. */ + "icon": PropTypes.object.isRequired, + +}; + +ItemAppBar.defaultProps = { + "title": "" +}; \ No newline at end of file diff --git a/src/components/ItemAppBar/ItemAppBar.stories.mdx b/src/components/ItemAppBar/ItemAppBar.stories.mdx new file mode 100644 index 0000000..e69de29 diff --git a/src/components/ItemAppBar/index.js b/src/components/ItemAppBar/index.js new file mode 100644 index 0000000..1a84e97 --- /dev/null +++ b/src/components/ItemAppBar/index.js @@ -0,0 +1,3 @@ +import ItemAppBar from "./ItemAppBar"; + +export default ItemAppBar; \ No newline at end of file diff --git a/src/components/ItemAppBarActions/ItemAppBarActions.js b/src/components/ItemAppBarActions/ItemAppBarActions.js new file mode 100644 index 0000000..66219af --- /dev/null +++ b/src/components/ItemAppBarActions/ItemAppBarActions.js @@ -0,0 +1,33 @@ +import React from "react"; +import PropTypes from 'prop-types'; +import { makeStyles, Tooltip, Typography, Toolbar, IconButton, Zoom, useTheme } from "@material-ui/core" + + +export default function ItemAppBarActions({ tooltipTitle, onClick, icon, }) { + + return ( + + + {icon} + + + ); +}; + +ItemAppBarActions.propTypes = { + /** The tooltip that appears when the icon is hovered over. */ + "toolbarTitle": PropTypes.string, + /** The function that is is ran when icon button is clicked */ + "onClick": PropTypes.func.isRequired, + /** The icon that is displayed inthe app bar. */ + "icon": PropTypes.object.isRequired, + +}; + +ItemAppBarActions.defaultProps = { + "toolbarTitle": "" +}; \ No newline at end of file diff --git a/src/components/ItemAppBarActions/ItemAppBarActions.stories.mdx b/src/components/ItemAppBarActions/ItemAppBarActions.stories.mdx new file mode 100644 index 0000000..5802fc1 --- /dev/null +++ b/src/components/ItemAppBarActions/ItemAppBarActions.stories.mdx @@ -0,0 +1,27 @@ +import { Meta, Story, Canvas, ArgsTable } from '@storybook/addon-docs/blocks'; +import ItemAppBarActions from "./ItemAppBarActions"; +import CloseItemViewIcon from '@material-ui/icons/ChevronRight'; + + + + +The ItemAppBarActions is the adds functionality to the appbar components. It allows the toolbars to perform actions like toggling darkmode or closing an item. + + + alert("You clicked this button") , + icon: , + }} + > + { args => } + + + + \ No newline at end of file diff --git a/src/components/ItemAppBarActions/index.js b/src/components/ItemAppBarActions/index.js new file mode 100644 index 0000000..13456f0 --- /dev/null +++ b/src/components/ItemAppBarActions/index.js @@ -0,0 +1,3 @@ +import ItemAppBarActions from "./ItemAppBarActions"; + +export default ItemAppBarActions; \ No newline at end of file diff --git a/src/components/ItemTableAppBar/ItemTableAppBar.js b/src/components/ItemTableAppBar/ItemTableAppBar.js index 86431ff..2dc969d 100644 --- a/src/components/ItemTableAppBar/ItemTableAppBar.js +++ b/src/components/ItemTableAppBar/ItemTableAppBar.js @@ -1,11 +1,14 @@ import React from "react"; import PropTypes from 'prop-types'; -import {makeStyles, Tooltip, Typography, AppBar, Toolbar, IconButton, Zoom, useTheme} from "@material-ui/core" +import { makeStyles, Tooltip, Typography, AppBar, Toolbar, IconButton, Zoom, useTheme } from "@material-ui/core" +import ItemAppBarActions from "../ItemAppBarActions"; + import DarkModeIcon from '@material-ui/icons/Brightness4'; import LightModeIcon from '@material-ui/icons/Brightness7'; +import { actions } from "react-table"; -export default function ItemTableAppBar({ title, setDarkMode }){ +export default function ItemTableAppBar({ title, action }) { const theme = useTheme(); const useStyles = makeStyles((theme) => ({ @@ -18,26 +21,23 @@ export default function ItemTableAppBar({ title, setDarkMode }){ })); const classes = useStyles(theme); const darkMode = theme.palette.type === "dark" + const setDarkMode = action + const toggleDarkMode = () => setDarkMode(!darkMode); - return( + return ( <> {title} - - - - {darkMode ? : } - - + : } + /> @@ -48,7 +48,7 @@ ItemTableAppBar.propTypes = { /** The title of the app bar. */ "title": PropTypes.string, /** Function to toggle darkMode. */ - "setDarkMode": PropTypes.func.isRequired, + "action": PropTypes.func.isRequired, }; ItemTableAppBar.defaultProps = { diff --git a/src/components/ItemViewAppBar/ItemViewAppBar.js b/src/components/ItemViewAppBar/ItemViewAppBar.js index 0dc081f..474e0a3 100644 --- a/src/components/ItemViewAppBar/ItemViewAppBar.js +++ b/src/components/ItemViewAppBar/ItemViewAppBar.js @@ -1,11 +1,13 @@ import React, { useEffect } from "react"; import { useHistory } from "react-router-dom"; import PropTypes from "prop-types"; -import {makeStyles, Tooltip, Typography, AppBar, Toolbar, IconButton, Zoom, useTheme} from "@material-ui/core" +import { makeStyles, Tooltip, Typography, AppBar, Toolbar, IconButton, Zoom, useTheme } from "@material-ui/core" import CloseItemViewIcon from '@material-ui/icons/ChevronRight'; +import ItemAppBarActions from "../ItemAppBarActions"; -export default function ItemViewAppBar({ title, setSidebarOpen }){ +export default function ItemViewAppBar({ title, action }) { + const setSidebarOpen = action useEffect(() => { setSidebarOpen(true) @@ -22,37 +24,30 @@ export default function ItemViewAppBar({ title, setSidebarOpen }){ }, appBarRoot: { width: "inherit", - + }, })); const classes = useStyles(theme); const history = useHistory(); - return( + return ( <> - - + - - { + { history.push("/"); }} - TransitionComponent={Zoom} - > - - - - - + icon={} + /> {title} - + ); } @@ -60,7 +55,7 @@ export default function ItemViewAppBar({ title, setSidebarOpen }){ ItemViewAppBar.propTypes = { /** Function to toggle sidebar open. */ - "setSidebarOpen": PropTypes.func.isRequired, + "action": PropTypes.func.isRequired, /** The title of the app bar. */ "title": PropTypes.string };