-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #276 from graasp/240/displayUsername
240/display username
- Loading branch information
Showing
6 changed files
with
158 additions
and
167 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { connect } from 'react-redux'; | ||
import { withStyles } from '@material-ui/core/styles'; | ||
import Tooltip from '@material-ui/core/Tooltip'; | ||
import IconButton from '@material-ui/core/IconButton'; | ||
import { Online, Offline } from 'react-detect-offline'; | ||
import Typography from '@material-ui/core/Typography/Typography'; | ||
import CloudIcon from '@material-ui/icons/Cloud'; | ||
import CloudOffIcon from '@material-ui/icons/CloudOff'; | ||
import { withTranslation } from 'react-i18next'; | ||
import ListItem from '@material-ui/core/ListItem'; | ||
import ChevronLeftIcon from '@material-ui/icons/ChevronLeft'; | ||
import ChevronRightIcon from '@material-ui/icons/ChevronRight'; | ||
import ListItemIcon from '@material-ui/core/ListItemIcon'; | ||
import ListItemSecondaryAction from '@material-ui/core/ListItemSecondaryAction'; | ||
import { DRAWER_HEADER_HEIGHT } from '../../config/constants'; | ||
|
||
const styles = () => ({ | ||
drawerHeader: { | ||
height: DRAWER_HEADER_HEIGHT, | ||
}, | ||
username: { | ||
fontWeight: 'bold', | ||
fontSize: '1rem', | ||
}, | ||
secondaryAction: { | ||
right: '5px', | ||
}, | ||
}); | ||
|
||
const DrawerHeader = ({ classes, theme, handleDrawerClose, username }) => { | ||
return ( | ||
<ListItem | ||
classes={{ root: classes.drawerHeader }} | ||
divider | ||
ContainerComponent="div" | ||
> | ||
<ListItemIcon> | ||
<Online> | ||
<CloudIcon /> | ||
</Online> | ||
<Offline> | ||
<CloudOffIcon /> | ||
</Offline> | ||
</ListItemIcon> | ||
|
||
<Tooltip title={username}> | ||
<Typography | ||
variant="inherit" | ||
color="inherit" | ||
noWrap | ||
classes={{ root: classes.username }} | ||
> | ||
{username} | ||
</Typography> | ||
</Tooltip> | ||
|
||
<ListItemSecondaryAction classes={{ root: classes.secondaryAction }}> | ||
<IconButton onClick={handleDrawerClose}> | ||
{theme.direction === 'ltr' ? ( | ||
<ChevronLeftIcon /> | ||
) : ( | ||
<ChevronRightIcon /> | ||
)} | ||
</IconButton> | ||
</ListItemSecondaryAction> | ||
</ListItem> | ||
); | ||
}; | ||
|
||
DrawerHeader.propTypes = { | ||
classes: PropTypes.shape({ | ||
username: PropTypes.string.isRequired, | ||
secondaryAction: PropTypes.string.isRequired, | ||
drawerHeader: PropTypes.string.isRequired, | ||
}).isRequired, | ||
theme: PropTypes.shape({ | ||
direction: PropTypes.string.isRequired, | ||
}).isRequired, | ||
handleDrawerClose: PropTypes.func.isRequired, | ||
username: PropTypes.string.isRequired, | ||
}; | ||
|
||
const mapStateToProps = ({ authentication }) => ({ | ||
username: authentication.getIn(['user', 'username']), | ||
}); | ||
|
||
const ConnectedComponent = connect(mapStateToProps, null)(DrawerHeader); | ||
|
||
const StyledComponent = withStyles(styles, { withTheme: true })( | ||
ConnectedComponent | ||
); | ||
|
||
const TranslatedComponent = withTranslation()(StyledComponent); | ||
|
||
export default TranslatedComponent; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.