From c6dd378f1159d4c7b9f806d929f69c15906ad1dc Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Thu, 18 Oct 2018 12:00:28 +0200 Subject: [PATCH] Nav Bar similar to Teams module --- client/src/components/LoggedInUser.js | 2 +- client/src/components/NavBar.js | 120 ++++++++++++++++---------- client/src/index.js | 77 +++++++++++++---- client/src/utils/local-storage.js | 9 ++ 4 files changed, 148 insertions(+), 60 deletions(-) create mode 100644 client/src/utils/local-storage.js diff --git a/client/src/components/LoggedInUser.js b/client/src/components/LoggedInUser.js index bca26b487..1d9fbad7e 100644 --- a/client/src/components/LoggedInUser.js +++ b/client/src/components/LoggedInUser.js @@ -9,7 +9,7 @@ import IconButton from '@material-ui/core/IconButton' import UserIcon from '@material-ui/icons/Person' import { Link } from 'react-router-dom' -const UserLink = props => +const UserLink = props => class LoggedInUser extends Component { diff --git a/client/src/components/NavBar.js b/client/src/components/NavBar.js index d7bd579dd..643149680 100644 --- a/client/src/components/NavBar.js +++ b/client/src/components/NavBar.js @@ -1,10 +1,11 @@ import React, { Component } from 'react' import PropTypes from 'prop-types' import { withStyles } from '@material-ui/core/styles' +import classNames from 'classnames' import AppBar from '@material-ui/core/AppBar' import Toolbar from '@material-ui/core/Toolbar' import Typography from '@material-ui/core/Typography' -import IconButton from '@material-ui/core/IconButton' +import Button from '@material-ui/core/Button' // icons import UsersIcon from '@material-ui/icons/People' @@ -18,13 +19,12 @@ import { Link } from 'react-router-dom' // components import LoggedInUser from './LoggedInUser' -const AboutLink = props => -const ContactLink = props => -const SearchLink = props => -const BrowseLink = props => -const HomeLink = props => +const HomeLink = props => +const BrowseLink = props => +const SearchLink = props => +const AboutLink = props => -const styles = { +const styles = theme => ({ root: { flexGrow: 1 }, @@ -35,8 +35,30 @@ const styles = { menuButton: { marginLeft: -12, marginRight: 20 + }, + cssRoot: { + color: '#FFFFFF', + backgroundColor: theme.palette.secondary, + '&:hover': { + backgroundColor: theme.palette.dark + }, + whiteSpace: 'nowrap', + paddingRight: 2 * theme.spacing.unit, + paddingLeft: 2 * theme.spacing.unit + }, + button: { + margin: theme.spacing.unit + }, + leftIcon: { + marginRight: theme.spacing.unit + }, + rightIcon: { + marginLeft: theme.spacing.unit + }, + iconSmall: { + fontSize: 20 } -} +}) class NavBar extends Component { @@ -60,50 +82,57 @@ class NavBar extends Component { this.setState({ authId: authId }) } } + render () { - const { classes } = this.props + const { classes, user, match } = this.props + console.log('NavBar: ', user, match) return (
- - Users + + Manage Users - - - - + + Home + + + + @@ -113,7 +142,10 @@ class NavBar extends Component { } NavBar.propTypes = { - classes: PropTypes.object.isRequired + classes: PropTypes.object.isRequired, + user: PropTypes.object, + match: PropTypes.object } export default withStyles(styles)(NavBar) + diff --git a/client/src/index.js b/client/src/index.js index ba9014416..e77b9c49f 100644 --- a/client/src/index.js +++ b/client/src/index.js @@ -1,11 +1,9 @@ import React, { Component } from 'react' - +import PropTypes from 'prop-types' import { Route, BrowserRouter, Switch } from 'react-router-dom' +import { hot } from 'react-hot-loader' -// Material UI - -import { MuiThemeProvider } from '@material-ui/core/styles' -import theme from './theme' +import { withStyles } from '@material-ui/core/styles' // Components import NavBar from './components/NavBar' @@ -16,24 +14,73 @@ import Search from './components/Search' import About from './components/About' import Contact from './components/Contact' +import { getItem } from './utils/local-storage' +import { + globalStyles +} from './theme' + class App extends Component { + constructor (props) { + super(props) + this.state = { + user: null + } + } + + async componentDidMount () { + let user = await getItem('user') + + if (user !== null && user !== undefined && user !== 'undefined') { + user = JSON.parse(user) + this.setState({ user: user }) + } + } + render () { + const { match } = this.props + return ( - - +
+ - - - - - - + + } + /> + } + /> + } + /> + } + /> + } + /> + - +
) } } -export default App +App.propTypes = { + auth: PropTypes.object +} + +const StyledApp = withStyles(globalStyles)(App) +export default hot(module)(StyledApp) diff --git a/client/src/utils/local-storage.js b/client/src/utils/local-storage.js new file mode 100644 index 000000000..963ba0f36 --- /dev/null +++ b/client/src/utils/local-storage.js @@ -0,0 +1,9 @@ +const getItem = async name => window.localStorage.getItem(name) +const setItem = async (name, value) => window.localStorage.setItem(name, value) +const removeItem = async name => window.localStorage.removeItem(name) + +export { + getItem, + setItem, + removeItem +}