Skip to content

Commit d95398b

Browse files
committed
feat: add teacher theme
closes #283
1 parent 6f65b6d commit d95398b

File tree

5 files changed

+142
-102
lines changed

5 files changed

+142
-102
lines changed

src/App.js

+89-78
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { withStyles } from '@material-ui/core';
77
import { withTranslation } from 'react-i18next';
88
import WifiIcon from '@material-ui/icons/Wifi';
99
import WifiOffIcon from '@material-ui/icons/WifiOff';
10+
import { MuiThemeProvider } from '@material-ui/core/styles';
1011
import Home from './Home';
1112
import VisitSpace from './components/VisitSpace';
1213
import SpacesNearby from './components/SpacesNearby';
@@ -22,6 +23,7 @@ import SignInScreen from './components/signin/SignInScreen';
2223
import Authorization from './components/Authorization';
2324
import Classrooms from './components/classrooms/Classrooms';
2425
import ImportDataScreen from './components/classrooms/ImportDataScreen';
26+
import { OnlineTheme, OfflineTheme } from './themes';
2527
import {
2628
SETTINGS_PATH,
2729
SYNC_SPACE_PATH,
@@ -81,6 +83,7 @@ export class App extends Component {
8183
toastrIcon: PropTypes.string.isRequired,
8284
}).isRequired,
8385
connexionStatus: PropTypes.bool.isRequired,
86+
userMode: PropTypes.oneOf(USER_MODES).isRequired,
8487
};
8588

8689
static defaultProps = {
@@ -155,86 +158,93 @@ export class App extends Component {
155158

156159
render() {
157160
const { height } = this.state;
161+
const { userMode, connexionStatus } = this.props;
158162

159163
return (
160-
<Router>
161-
<div className="app" style={{ height }}>
162-
<Switch>
163-
<Route exact path={SIGN_IN_PATH} component={SignInScreen} />
164-
<Route exact path={HOME_PATH} component={Authorization()(Home)} />
165-
<Route
166-
exact
167-
path={SAVED_SPACES_PATH}
168-
component={Authorization()(SavedSpaces)}
169-
/>
170-
<Route
171-
exact
172-
path={SPACES_NEARBY_PATH}
173-
component={Authorization()(SpacesNearby)}
174-
/>
175-
<Route
176-
exact
177-
path={VISIT_PATH}
178-
component={Authorization()(VisitSpace)}
179-
/>
180-
<Route
181-
exact
182-
path={LOAD_SPACE_PATH}
183-
component={Authorization()(LoadSpace)}
184-
/>
185-
<Route
186-
exact
187-
path={LOAD_SELECTION_SPACE_PATH}
188-
component={Authorization()(LoadSelectionScreen)}
189-
/>
190-
<Route
191-
exact
192-
path={SETTINGS_PATH}
193-
component={Authorization()(Settings)}
194-
/>
195-
<Route
196-
exact
197-
path={SYNC_SPACE_PATH}
198-
component={Authorization()(SyncScreen)}
199-
/>
200-
<Route
201-
exact
202-
path={buildExportSelectionPathForSpaceId()}
203-
component={Authorization()(ExportSelectionScreen)}
204-
/>
205-
<Route
206-
exact
207-
path={SPACE_PATH}
208-
component={Authorization()(SpaceScreen)}
209-
/>
210-
<Route
211-
exact
212-
path={DASHBOARD_PATH}
213-
component={Authorization()(Dashboard)}
214-
/>
215-
<Route
216-
exact
217-
path={buildClassroomPath()}
218-
component={Authorization([USER_MODES.TEACHER])(ClassroomScreen)}
219-
/>
220-
<Route
221-
exact
222-
path={CLASSROOMS_PATH}
223-
component={Authorization([USER_MODES.TEACHER])(Classrooms)}
224-
/>
225-
<Route
226-
exact
227-
path={buildImportDataInClassroomPath()}
228-
component={Authorization([USER_MODES.TEACHER])(ImportDataScreen)}
229-
/>
230-
<Route
231-
exact
232-
path={DEVELOPER_PATH}
233-
component={Authorization()(DeveloperScreen)}
234-
/>
235-
</Switch>
236-
</div>
237-
</Router>
164+
<MuiThemeProvider
165+
theme={connexionStatus ? OnlineTheme(userMode) : OfflineTheme}
166+
>
167+
<Router>
168+
<div className="app" style={{ height }}>
169+
<Switch>
170+
<Route exact path={SIGN_IN_PATH} component={SignInScreen} />
171+
<Route exact path={HOME_PATH} component={Authorization()(Home)} />
172+
<Route
173+
exact
174+
path={SAVED_SPACES_PATH}
175+
component={Authorization()(SavedSpaces)}
176+
/>
177+
<Route
178+
exact
179+
path={SPACES_NEARBY_PATH}
180+
component={Authorization()(SpacesNearby)}
181+
/>
182+
<Route
183+
exact
184+
path={VISIT_PATH}
185+
component={Authorization()(VisitSpace)}
186+
/>
187+
<Route
188+
exact
189+
path={LOAD_SPACE_PATH}
190+
component={Authorization()(LoadSpace)}
191+
/>
192+
<Route
193+
exact
194+
path={LOAD_SELECTION_SPACE_PATH}
195+
component={Authorization()(LoadSelectionScreen)}
196+
/>
197+
<Route
198+
exact
199+
path={SETTINGS_PATH}
200+
component={Authorization()(Settings)}
201+
/>
202+
<Route
203+
exact
204+
path={SYNC_SPACE_PATH}
205+
component={Authorization()(SyncScreen)}
206+
/>
207+
<Route
208+
exact
209+
path={buildExportSelectionPathForSpaceId()}
210+
component={Authorization()(ExportSelectionScreen)}
211+
/>
212+
<Route
213+
exact
214+
path={SPACE_PATH}
215+
component={Authorization()(SpaceScreen)}
216+
/>
217+
<Route
218+
exact
219+
path={DASHBOARD_PATH}
220+
component={Authorization()(Dashboard)}
221+
/>
222+
<Route
223+
exact
224+
path={buildClassroomPath()}
225+
component={Authorization([USER_MODES.TEACHER])(ClassroomScreen)}
226+
/>
227+
<Route
228+
exact
229+
path={CLASSROOMS_PATH}
230+
component={Authorization([USER_MODES.TEACHER])(Classrooms)}
231+
/>
232+
<Route
233+
exact
234+
path={buildImportDataInClassroomPath()}
235+
component={Authorization([USER_MODES.TEACHER])(
236+
ImportDataScreen
237+
)}
238+
/>
239+
<Route
240+
exact
241+
path={DEVELOPER_PATH}
242+
component={Authorization()(DeveloperScreen)}
243+
/>
244+
</Switch>
245+
</div>
246+
</Router>
247+
</MuiThemeProvider>
238248
);
239249
}
240250
}
@@ -246,6 +256,7 @@ const mapStateToProps = ({ authentication }) => ({
246256
'settings',
247257
'geolocationEnabled',
248258
]),
259+
userMode: authentication.getIn(['user', 'settings', 'userMode']),
249260
});
250261

251262
const mapDispatchToProps = {

src/components/common/DrawerHeader.js

+27-11
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,20 @@ import { connect } from 'react-redux';
44
import { withStyles } from '@material-ui/core/styles';
55
import Tooltip from '@material-ui/core/Tooltip';
66
import IconButton from '@material-ui/core/IconButton';
7-
import { Online, Offline } from 'react-detect-offline';
87
import Typography from '@material-ui/core/Typography/Typography';
9-
import CloudIcon from '@material-ui/icons/Cloud';
10-
import CloudOffIcon from '@material-ui/icons/CloudOff';
8+
import PersonIcon from '@material-ui/icons/Person';
119
import { withTranslation } from 'react-i18next';
1210
import ListItem from '@material-ui/core/ListItem';
11+
import TeacherIcon from '@material-ui/icons/School';
1312
import ChevronLeftIcon from '@material-ui/icons/ChevronLeft';
1413
import ChevronRightIcon from '@material-ui/icons/ChevronRight';
1514
import ListItemIcon from '@material-ui/core/ListItemIcon';
1615
import ListItemSecondaryAction from '@material-ui/core/ListItemSecondaryAction';
17-
import { DRAWER_HEADER_HEIGHT } from '../../config/constants';
16+
import {
17+
DRAWER_HEADER_HEIGHT,
18+
USER_MODES,
19+
THEME_COLORS,
20+
} from '../../config/constants';
1821

1922
const styles = () => ({
2023
drawerHeader: {
@@ -27,22 +30,30 @@ const styles = () => ({
2730
secondaryAction: {
2831
right: '5px',
2932
},
33+
teacherColor: {
34+
color: THEME_COLORS[USER_MODES.TEACHER],
35+
},
3036
});
3137

32-
const DrawerHeader = ({ classes, theme, handleDrawerClose, username }) => {
38+
const DrawerHeader = ({
39+
classes,
40+
theme,
41+
handleDrawerClose,
42+
username,
43+
isTeacher,
44+
}) => {
3345
return (
3446
<ListItem
3547
classes={{ root: classes.drawerHeader }}
3648
divider
3749
ContainerComponent="div"
3850
>
3951
<ListItemIcon>
40-
<Online>
41-
<CloudIcon />
42-
</Online>
43-
<Offline>
44-
<CloudOffIcon />
45-
</Offline>
52+
{isTeacher ? (
53+
<TeacherIcon className={classes.teacherColor} />
54+
) : (
55+
<PersonIcon />
56+
)}
4657
</ListItemIcon>
4758

4859
<Tooltip title={username}>
@@ -74,16 +85,21 @@ DrawerHeader.propTypes = {
7485
username: PropTypes.string.isRequired,
7586
secondaryAction: PropTypes.string.isRequired,
7687
drawerHeader: PropTypes.string.isRequired,
88+
teacherColor: PropTypes.string.isRequired,
7789
}).isRequired,
7890
theme: PropTypes.shape({
7991
direction: PropTypes.string.isRequired,
8092
}).isRequired,
8193
handleDrawerClose: PropTypes.func.isRequired,
8294
username: PropTypes.string.isRequired,
95+
isTeacher: PropTypes.bool.isRequired,
8396
};
8497

8598
const mapStateToProps = ({ authentication }) => ({
8699
username: authentication.getIn(['user', 'username']),
100+
isTeacher:
101+
authentication.getIn(['user', 'settings', 'userMode']) ===
102+
USER_MODES.TEACHER,
87103
});
88104

89105
const ConnectedComponent = connect(mapStateToProps, null)(DrawerHeader);

src/config/constants.js

+5
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ export const USER_MODES = {
1414
TEACHER: 'teacher',
1515
};
1616
export const DEFAULT_USER_MODE = USER_MODES.TEACHER;
17+
export const THEME_COLORS = {
18+
[DEFAULT_USER_MODE]: '#5050d2',
19+
[USER_MODES.STUDENT]: '#5050d2',
20+
[USER_MODES.TEACHER]: '#3A31AF',
21+
};
1722
export const SHORT_ID_LENGTH = 6;
1823
export const LONG_ID_LENGTH = 24;
1924
export const SMART_GATEWAY_HOST = 'gateway.golabz.eu';

src/index.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { Provider } from 'react-redux';
55
import * as Sentry from '@sentry/browser';
66
import ReduxToastr from 'react-redux-toastr';
77
import { Detector } from 'react-detect-offline';
8-
import { MuiThemeProvider } from '@material-ui/core/styles';
98
import { I18nextProvider } from 'react-i18next';
109
import katex from 'katex';
1110
import i18nConfig from './config/i18n';
@@ -14,7 +13,6 @@ import 'react-redux-toastr/lib/css/react-redux-toastr.min.css';
1413
import 'katex/dist/katex.min.css';
1514
import 'react-quill/dist/quill.core.css';
1615
import App from './App';
17-
import { OnlineTheme, OfflineTheme } from './themes';
1816
import configureStore from './store/configure';
1917

2018
// bind katex to the window object
@@ -42,14 +40,14 @@ ReactDOM.render(
4240
<I18nextProvider i18n={i18nConfig}>
4341
<Detector
4442
render={({ online }) => (
45-
<MuiThemeProvider theme={online ? OnlineTheme : OfflineTheme}>
43+
<>
4644
<ReduxToastr
4745
transitionIn="fadeIn"
4846
preventDuplicates
4947
transitionOut="fadeOut"
5048
/>
5149
<App connexionStatus={online} />
52-
</MuiThemeProvider>
50+
</>
5351
)}
5452
/>
5553
</I18nextProvider>

src/themes/OnlineTheme.js

+19-9
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,23 @@
11
import { createMuiTheme } from '@material-ui/core/styles';
2+
import { THEME_COLORS, DEFAULT_USER_MODE } from '../config/constants';
23

3-
const OnlineTheme = createMuiTheme({
4-
typography: {
5-
useNextVariants: true,
6-
},
7-
palette: {
8-
primary: { light: '#5050d2', main: '#5050d2', dark: '#5050d2' },
9-
secondary: { light: '#ffffff', main: '#ffffff', dark: '#ffffff' },
10-
},
11-
});
4+
const OnlineTheme = userMode => {
5+
// user mode define primary colors
6+
const themeColor =
7+
userMode in THEME_COLORS
8+
? THEME_COLORS[userMode]
9+
: THEME_COLORS[DEFAULT_USER_MODE];
10+
const primary = { light: themeColor, main: themeColor, dark: themeColor };
11+
12+
return createMuiTheme({
13+
typography: {
14+
useNextVariants: true,
15+
},
16+
palette: {
17+
primary,
18+
secondary: { light: '#ffffff', main: '#ffffff', dark: '#ffffff' },
19+
},
20+
});
21+
};
1222

1323
export default OnlineTheme;

0 commit comments

Comments
 (0)