Skip to content

Commit 414cec5

Browse files
committed
feat: add welcome screen when there si nothing to display in Home
closes #273
1 parent df45a4a commit 414cec5

File tree

3 files changed

+141
-3
lines changed

3 files changed

+141
-3
lines changed

src/Home.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import Typography from '@material-ui/core/Typography';
1313
import FavoriteIcon from '@material-ui/icons/Star';
1414
import HistoryIcon from '@material-ui/icons/History';
1515
import Divider from '@material-ui/core/Divider';
16-
import NoSpacesAvailable from './components/common/NoSpacesAvailable';
1716
import {
1817
HOME_MAIN_ID,
1918
FAVORITE_SPACES_WRAPPER_ID,
@@ -26,6 +25,7 @@ import SpaceGrid from './components/space/SpaceGrid';
2625
import Loader from './components/common/Loader';
2726
import Main from './components/common/Main';
2827
import { HOME_PATH } from './config/paths';
28+
import WelcomeContent from './components/common/WelcomeContent';
2929

3030
const styles = theme => ({
3131
...Styles(theme),
@@ -175,7 +175,7 @@ class Home extends Component {
175175
};
176176

177177
render() {
178-
const { classes, activity } = this.props;
178+
const { classes, activity, spaces } = this.props;
179179
const { filteredFavoriteSpaces, filteredRecentSpaces } = this.state;
180180

181181
const noSpacesAvailable =
@@ -198,7 +198,7 @@ class Home extends Component {
198198
return (
199199
<Main showSearch handleOnSearch={this.handleOnSearch} id={HOME_MAIN_ID}>
200200
{noSpacesAvailable ? (
201-
<NoSpacesAvailable />
201+
<WelcomeContent hasSavedSpaces={spaces.size > 0} />
202202
) : (
203203
<div>
204204
{this.renderRecentSpaces()}
+138
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
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);

src/data/icon.png

49.2 KB
Loading

0 commit comments

Comments
 (0)