Nav Bar similar to Teams module
This commit is contained in:
1 parent
77e16dff7b
commit
c6dd378f11
4 files changed
+148
-60
No files matched your search
@@ -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 => <Link to='/user' {...props} />
|
||||
const UserLink = props => <Link to='/users/user' {...props} />
|
||||
|
||||
class LoggedInUser extends Component {
|
||||
|
||||
|
||||
@@ -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 => <Link to='/about' {...props} />
|
||||
const ContactLink = props => <Link to='/contact' {...props} />
|
||||
const SearchLink = props => <Link to='/search' {...props} />
|
||||
const BrowseLink = props => <Link to='/browse' {...props} />
|
||||
const HomeLink = props => <Link to='/' {...props} />
|
||||
const HomeLink = props => <Link to='/users' {...props} />
|
||||
const BrowseLink = props => <Link to='/users/browse' {...props} />
|
||||
const SearchLink = props => <Link to='/users/search' {...props} />
|
||||
const AboutLink = props => <Link to='/users/about' {...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 (
|
||||
<div className={classes.root}>
|
||||
<AppBar position='static' color='secondary'>
|
||||
<Toolbar>
|
||||
<Typography variant='title' color='inherit' className={classes.flex}>
|
||||
Users
|
||||
<Typography variant='h5' color='inherit' className={classes.flex}>
|
||||
Manage Users
|
||||
</Typography>
|
||||
<IconButton
|
||||
className={classes.menuButton}
|
||||
color='inherit'
|
||||
title='Users Module Home'
|
||||
component={HomeLink}>
|
||||
<UsersIcon />
|
||||
</IconButton>
|
||||
<IconButton
|
||||
className={classes.menuButton}
|
||||
color='inherit'
|
||||
<Button
|
||||
variant='text'
|
||||
size='small'
|
||||
className={classNames(classes.button, classes.cssRoot)}
|
||||
title='Users Home'
|
||||
component={HomeLink}
|
||||
to={`${match.url}`}>
|
||||
<UsersIcon className={classNames(classes.leftIcon, classes.iconSmall)} />
|
||||
Home
|
||||
</Button>
|
||||
<Button
|
||||
variant='text'
|
||||
size='small'
|
||||
className={classNames(classes.button, classes.cssRoot)}
|
||||
title='Browse the Users Directory'
|
||||
component={BrowseLink}>
|
||||
<BrowseIcon />
|
||||
</IconButton>
|
||||
<IconButton
|
||||
className={classes.menuButton}
|
||||
color='inherit'
|
||||
component={BrowseLink}
|
||||
to={`${match.url}/browse`}>
|
||||
<BrowseIcon className={classNames(classes.leftIcon, classes.iconSmall)} />
|
||||
Directory
|
||||
</Button>
|
||||
<Button
|
||||
variant='text'
|
||||
size='small'
|
||||
className={classNames(classes.button, classes.cssRoot)}
|
||||
title='Search Users'
|
||||
component={SearchLink}>
|
||||
<SearchIcon />
|
||||
</IconButton>
|
||||
<IconButton
|
||||
className={classes.menuButton}
|
||||
color='inherit'
|
||||
title='Contact Form'
|
||||
component={ContactLink}>
|
||||
<ContactIcon />
|
||||
</IconButton>
|
||||
<IconButton
|
||||
className={classes.menuButton}
|
||||
color='inherit'
|
||||
component={SearchLink}
|
||||
to={`${match.url}/search`}>
|
||||
<SearchIcon className={classNames(classes.leftIcon, classes.iconSmall)} />
|
||||
Search
|
||||
</Button>
|
||||
<Button
|
||||
variant='text'
|
||||
size='small'
|
||||
className={classNames(classes.button, classes.cssRoot)}
|
||||
title='About the Users Module'
|
||||
component={AboutLink}>
|
||||
<AboutIcon />
|
||||
</IconButton>
|
||||
component={AboutLink}
|
||||
to={`${match.url}/about`}>
|
||||
<AboutIcon className={classNames(classes.leftIcon, classes.iconSmall)} />
|
||||
About
|
||||
</Button>
|
||||
<LoggedInUser authId={this.state.authId} />
|
||||
</Toolbar>
|
||||
</AppBar>
|
||||
@@ -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)
|
||||
|
||||
+62
-15
@@ -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 (
|
||||
<BrowserRouter>
|
||||
<MuiThemeProvider theme={theme}>
|
||||
<NavBar />
|
||||
<div className='App'>
|
||||
<NavBar match={match} user={this.state.user} />
|
||||
<Switch>
|
||||
<Route exact path='/' component={Home} />
|
||||
<Route path='/user' component={User} />
|
||||
<Route path='/browse' component={Browse} />
|
||||
<Route path='/search' component={Search} />
|
||||
<Route path='/about' component={About} />
|
||||
<Route path='/contact' component={Contact} />
|
||||
<Route exact path={`${match.path}`} component={Home} />
|
||||
<Route
|
||||
exact
|
||||
path={`${match.path}/users`}
|
||||
render={props => <Home {...props} auth={this.props.auth} />}
|
||||
/>
|
||||
<Route
|
||||
exact
|
||||
path={`${match.path}/user`}
|
||||
render={props => <User {...props} auth={this.props.auth} />}
|
||||
/>
|
||||
<Route
|
||||
exact
|
||||
path={`${match.path}/browse`}
|
||||
render={props => <Browse {...props} auth={this.props.auth} />}
|
||||
/>
|
||||
<Route
|
||||
exact
|
||||
path={`${match.path}/search`}
|
||||
render={props => <Search {...props} auth={this.props.auth} />}
|
||||
/>
|
||||
<Route
|
||||
exact
|
||||
path={`${match.path}/about`}
|
||||
render={props => <About {...props} auth={this.props.auth} />}
|
||||
/>
|
||||
<Route path='/browse/:slug' component={Browse} />
|
||||
</Switch>
|
||||
</MuiThemeProvider>
|
||||
</div>
|
||||
</BrowserRouter>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
export default App
|
||||
App.propTypes = {
|
||||
auth: PropTypes.object
|
||||
}
|
||||
|
||||
const StyledApp = withStyles(globalStyles)(App)
|
||||
export default hot(module)(StyledApp)
|
||||
@@ -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
|
||||
}
|
||||
Reference in new issue
Block a user