|
| 1 | +import React, { Component } from 'react'; |
| 2 | +import PropTypes from 'prop-types'; |
| 3 | +import { withStyles } from '@material-ui/core/styles'; |
| 4 | +import { withRouter } from 'react-router'; |
| 5 | +import { withTranslation } from 'react-i18next'; |
| 6 | +import Typography from '@material-ui/core/Typography/Typography'; |
| 7 | +import { Online } from 'react-detect-offline'; |
| 8 | +import Button from '@material-ui/core/Button'; |
| 9 | +import ButtonGroup from '@material-ui/core/ButtonGroup'; |
| 10 | +import Styles from '../../Styles'; |
| 11 | +import logo from '../../data/icon.png'; |
| 12 | +import { |
| 13 | + SAVED_SPACES_PATH, |
| 14 | + VISIT_PATH, |
| 15 | + LOAD_SPACE_PATH, |
| 16 | +} from '../../config/paths'; |
| 17 | + |
| 18 | +const styles = theme => ({ |
| 19 | + ...Styles(theme), |
| 20 | + wrapper: { |
| 21 | + display: 'flex', |
| 22 | + |
| 23 | + alignItems: 'center', |
| 24 | + justifyContent: 'center', |
| 25 | + alignContent: 'center', |
| 26 | + flexDirection: 'column', |
| 27 | + height: '80%', |
| 28 | + |
| 29 | + '& .MuiButtonGroup-groupedContainedPrimary:not(:last-child)': { |
| 30 | + borderColor: 'white', |
| 31 | + }, |
| 32 | + }, |
| 33 | + graaspLogo: { |
| 34 | + width: '35%', |
| 35 | + maxWidth: '400px', |
| 36 | + minWidth: '200px', |
| 37 | + marginTop: theme.spacing(3), |
| 38 | + }, |
| 39 | + |
| 40 | + // similar layout to buttons in ButtonGroup for wrapped buttons |
| 41 | + wrappedButton: { |
| 42 | + background: theme.palette.primary.main, |
| 43 | + borderRadius: 0, |
| 44 | + borderRight: '1px solid white', |
| 45 | + color: 'white', |
| 46 | + padding: theme.spacing(0, 3), |
| 47 | + |
| 48 | + '&:hover': { |
| 49 | + background: theme.palette.primary.main, |
| 50 | + }, |
| 51 | + // add border radius when is last button |
| 52 | + '&.MuiButtonBase-root:last-child': { |
| 53 | + borderTopRightRadius: '4px', |
| 54 | + borderBottomRightRadius: '4px', |
| 55 | + }, |
| 56 | + }, |
| 57 | +}); |
| 58 | + |
| 59 | +class WelcomeContent extends Component { |
| 60 | + static propTypes = { |
| 61 | + classes: PropTypes.shape({ |
| 62 | + graaspLogo: PropTypes.string.isRequired, |
| 63 | + wrappedButton: PropTypes.string.isRequired, |
| 64 | + wrapper: PropTypes.string.isRequired, |
| 65 | + }).isRequired, |
| 66 | + t: PropTypes.func.isRequired, |
| 67 | + history: PropTypes.shape({ |
| 68 | + push: PropTypes.func.isRequired, |
| 69 | + }).isRequired, |
| 70 | + hasSavedSpaces: PropTypes.bool.isRequired, |
| 71 | + }; |
| 72 | + |
| 73 | + handleGoToVisitSpace = () => { |
| 74 | + const { |
| 75 | + history: { push }, |
| 76 | + } = this.props; |
| 77 | + push(VISIT_PATH); |
| 78 | + }; |
| 79 | + |
| 80 | + handleGoToLoadSpace = () => { |
| 81 | + const { |
| 82 | + history: { push }, |
| 83 | + } = this.props; |
| 84 | + push(LOAD_SPACE_PATH); |
| 85 | + }; |
| 86 | + |
| 87 | + handleGoToSavedSpaces = () => { |
| 88 | + const { |
| 89 | + history: { push }, |
| 90 | + } = this.props; |
| 91 | + push(SAVED_SPACES_PATH); |
| 92 | + }; |
| 93 | + |
| 94 | + render() { |
| 95 | + const { classes, t, hasSavedSpaces } = this.props; |
| 96 | + return ( |
| 97 | + <div className={classes.wrapper}> |
| 98 | + <img src={logo} alt={t('Graasp logo')} className={classes.graaspLogo} /> |
| 99 | + <Typography variant="h4" color="inherit" style={{ margin: '2rem' }}> |
| 100 | + {t('Welcome to Graasp Desktop')} |
| 101 | + </Typography> |
| 102 | + <ButtonGroup |
| 103 | + disableElevation |
| 104 | + variant="contained" |
| 105 | + color="primary" |
| 106 | + aria-label="contained group primary button" |
| 107 | + > |
| 108 | + <Button onClick={this.handleGoToLoadSpace}> |
| 109 | + {t('Load a Space')} |
| 110 | + </Button> |
| 111 | + , |
| 112 | + <Online> |
| 113 | + { |
| 114 | + // class wrappedButton is necessary to match the layout when encapsulated with Online tag |
| 115 | + } |
| 116 | + <Button |
| 117 | + className={classes.wrappedButton} |
| 118 | + onClick={this.handleGoToVisitSpace} |
| 119 | + > |
| 120 | + {t('Visit a Space')} |
| 121 | + </Button> |
| 122 | + </Online> |
| 123 | + {hasSavedSpaces && ( |
| 124 | + <Button onClick={this.handleGoToSavedSpaces}> |
| 125 | + {t('Go to Saved Spaces')} |
| 126 | + </Button> |
| 127 | + )} |
| 128 | + </ButtonGroup> |
| 129 | + </div> |
| 130 | + ); |
| 131 | + } |
| 132 | +} |
| 133 | + |
| 134 | +const StyledComponent = withStyles(styles, { withTheme: true })(WelcomeContent); |
| 135 | + |
| 136 | +const TranslatedComponent = withTranslation()(StyledComponent); |
| 137 | + |
| 138 | +export default withRouter(TranslatedComponent); |
0 commit comments