Skip to content

Commit dbd1c06

Browse files
committed
feat: hide dev mode, sync and deletion when student mode is enabled
1 parent 05652a2 commit dbd1c06

File tree

5 files changed

+81
-19
lines changed

5 files changed

+81
-19
lines changed

src/components/Settings.js

+18-3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import PropTypes from 'prop-types';
33
import { withRouter } from 'react-router';
44
import { withStyles } from '@material-ui/core/styles';
55
import Typography from '@material-ui/core/Typography';
6+
import { connect } from 'react-redux';
67
import { FormGroup } from '@material-ui/core';
78
import { withTranslation } from 'react-i18next';
89
import Styles from '../Styles';
@@ -13,6 +14,7 @@ import Main from './common/Main';
1314
import { SETTINGS_MAIN_ID } from '../config/selectors';
1415
import SyncAdvancedSwitch from './space/sync/SyncAdvancedSwitch';
1516
import StudentModeSwitch from './common/StudentModeSwitch';
17+
import { DEFAULT_STUDENT_MODE } from '../config/constants';
1618

1719
// eslint-disable-next-line react/prefer-stateless-function
1820
export class Settings extends Component {
@@ -29,10 +31,15 @@ export class Settings extends Component {
2931
i18n: PropTypes.shape({
3032
changeLanguage: PropTypes.func.isRequired,
3133
}).isRequired,
34+
studentMode: PropTypes.bool,
35+
};
36+
37+
static defaultProps = {
38+
studentMode: DEFAULT_STUDENT_MODE,
3239
};
3340

3441
render() {
35-
const { classes, t } = this.props;
42+
const { classes, t, studentMode } = this.props;
3643

3744
return (
3845
<Main id={SETTINGS_MAIN_ID}>
@@ -42,18 +49,26 @@ export class Settings extends Component {
4249
</Typography>
4350
<FormGroup>
4451
<LanguageSelect />
45-
<DeveloperSwitch />
4652
<GeolocationControl />
4753
<SyncAdvancedSwitch />
4854
<StudentModeSwitch />
55+
{studentMode ? null : <DeveloperSwitch />}
4956
</FormGroup>
5057
</div>
5158
</Main>
5259
);
5360
}
5461
}
5562

56-
const StyledComponent = withStyles(Styles, { withTheme: true })(Settings);
63+
const mapStateToProps = ({ authentication }) => ({
64+
studentMode: authentication.getIn(['user', 'settings', 'studentMode']),
65+
});
66+
67+
const ConnectedComponent = connect(mapStateToProps, null)(Settings);
68+
69+
const StyledComponent = withStyles(Styles, { withTheme: true })(
70+
ConnectedComponent
71+
);
5772

5873
const TranslatedComponent = withTranslation()(StyledComponent);
5974

src/components/__snapshots__/Settings.test.js.snap

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ exports[`<Settings /> renders correctly 1`] = `
1515
</WithStyles(ForwardRef(Typography))>
1616
<WithStyles(ForwardRef(FormGroup))>
1717
<withI18nextTranslation(WithStyles(Connect(LanguageSelect))) />
18-
<withI18nextTranslation(WithStyles(Connect(DeveloperSwitch))) />
1918
<withI18nextTranslation(WithStyles(Connect(GeolocationControl))) />
2019
<withI18nextTranslation(WithStyles(Connect(SyncAdvancedSwitch))) />
2120
<withI18nextTranslation(WithStyles(Connect(StudentModeSwitch))) />
21+
<withI18nextTranslation(WithStyles(Connect(DeveloperSwitch))) />
2222
</WithStyles(ForwardRef(FormGroup))>
2323
</div>
2424
</withI18nextTranslation(WithStyles(Connect(Main)))>

src/components/common/MediaCard.js

+33-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React from 'react';
22
import PropTypes from 'prop-types';
33
import clsx from 'clsx';
4+
import { connect } from 'react-redux';
45
import { withStyles } from '@material-ui/core/styles';
56
import Card from '@material-ui/core/Card';
67
import CardActionArea from '@material-ui/core/CardActionArea';
@@ -16,7 +17,7 @@ import ClearButton from '../space/ClearButton';
1617
import ExportButton from '../space/ExportButton';
1718
import SyncButton from '../space/SyncButton';
1819
import Text from './Text';
19-
import { MIN_CARD_WIDTH } from '../../config/constants';
20+
import { MIN_CARD_WIDTH, DEFAULT_STUDENT_MODE } from '../../config/constants';
2021
import {
2122
buildSpaceCardId,
2223
SPACE_DESCRIPTION_EXPAND_BUTTON_CLASS,
@@ -56,13 +57,33 @@ const styles = theme => ({
5657
});
5758

5859
export const MediaCard = props => {
59-
const { classes, image, text, viewLink, space, showActions } = props;
60+
const {
61+
classes,
62+
image,
63+
text,
64+
viewLink,
65+
space,
66+
showActions,
67+
studentMode,
68+
} = props;
6069
const { id, name } = space;
6170
const [expanded, setExpanded] = React.useState(false);
6271
const handleExpandClick = () => {
6372
setExpanded(!expanded);
6473
};
6574

75+
const renderTeacherActions = () => {
76+
if (!studentMode) {
77+
return (
78+
<>
79+
<DeleteButton spaceId={id} />
80+
<SyncButton spaceId={id} />
81+
</>
82+
);
83+
}
84+
return null;
85+
};
86+
6687
return (
6788
<Card id={buildSpaceCardId(id)} className={classes.card}>
6889
<CardActionArea className={SPACE_CARD_LINK_CLASS} onClick={viewLink}>
@@ -88,9 +109,8 @@ export const MediaCard = props => {
88109
{showActions && (
89110
<CardActions disableSpacing>
90111
<ClearButton spaceId={id} />
91-
<DeleteButton spaceId={id} />
92112
<ExportButton space={space} />
93-
<SyncButton spaceId={id} />
113+
{renderTeacherActions()}
94114

95115
{text && (
96116
<IconButton
@@ -131,11 +151,19 @@ MediaCard.propTypes = {
131151
text: PropTypes.string,
132152
viewLink: PropTypes.func.isRequired,
133153
showActions: PropTypes.bool,
154+
studentMode: PropTypes.bool,
134155
};
135156

136157
MediaCard.defaultProps = {
137158
text: '',
138159
showActions: false,
160+
studentMode: DEFAULT_STUDENT_MODE,
139161
};
140162

141-
export default withStyles(styles)(MediaCard);
163+
const mapStateToProps = ({ authentication }) => ({
164+
studentMode: authentication.getIn(['user', 'settings', 'studentMode']),
165+
});
166+
167+
const ConnectedComponent = connect(mapStateToProps, null)(MediaCard);
168+
169+
export default withStyles(styles)(ConnectedComponent);

src/components/common/__snapshots__/MediaCard.test.js.snap

+6-6
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,6 @@ exports[`<MediaCard /> <MediaCard /> with showActions = true with text defined r
8989
<Connect(withI18nextTranslation(WithStyles(ClearButton)))
9090
spaceId="id"
9191
/>
92-
<withI18nextTranslation(WithStyles(Connect(DeleteButton)))
93-
spaceId="id"
94-
/>
9592
<withI18nextTranslation(WithStyles(Connect(ExportButton)))
9693
space={
9794
Object {
@@ -100,6 +97,9 @@ exports[`<MediaCard /> <MediaCard /> with showActions = true with text defined r
10097
}
10198
}
10299
/>
100+
<withI18nextTranslation(WithStyles(Connect(DeleteButton)))
101+
spaceId="id"
102+
/>
103103
<withRouter(withI18nextTranslation(WithStyles(SyncButton)))
104104
spaceId="id"
105105
/>
@@ -161,9 +161,6 @@ exports[`<MediaCard /> <MediaCard /> with showActions = true with text undefined
161161
<Connect(withI18nextTranslation(WithStyles(ClearButton)))
162162
spaceId="id"
163163
/>
164-
<withI18nextTranslation(WithStyles(Connect(DeleteButton)))
165-
spaceId="id"
166-
/>
167164
<withI18nextTranslation(WithStyles(Connect(ExportButton)))
168165
space={
169166
Object {
@@ -172,6 +169,9 @@ exports[`<MediaCard /> <MediaCard /> with showActions = true with text undefined
172169
}
173170
}
174171
/>
172+
<withI18nextTranslation(WithStyles(Connect(DeleteButton)))
173+
spaceId="id"
174+
/>
175175
<withRouter(withI18nextTranslation(WithStyles(SyncButton)))
176176
spaceId="id"
177177
/>

src/components/space/SpaceHeader.js

+23-4
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {
2525
SPACE_PREVIEW_ICON_CLASS,
2626
DRAWER_BUTTON_ID,
2727
} from '../../config/selectors';
28+
import { DEFAULT_STUDENT_MODE } from '../../config/constants';
2829

2930
class SpaceHeader extends Component {
3031
static propTypes = {
@@ -45,6 +46,11 @@ class SpaceHeader extends Component {
4546
handleDrawerOpen: PropTypes.func.isRequired,
4647
dispatchSaveSpace: PropTypes.func.isRequired,
4748
t: PropTypes.func.isRequired,
49+
studentMode: PropTypes.bool,
50+
};
51+
52+
static defaultProps = {
53+
studentMode: DEFAULT_STUDENT_MODE,
4854
};
4955

5056
handleSave = () => {
@@ -138,6 +144,20 @@ class SpaceHeader extends Component {
138144
return null;
139145
}
140146

147+
renderTeacherButtons() {
148+
const { studentMode } = this.props;
149+
if (!studentMode) {
150+
return (
151+
<>
152+
{this.renderDeleteButton()}
153+
{this.renderSyncButton()}
154+
{this.renderSaveButton()}
155+
</>
156+
);
157+
}
158+
return null;
159+
}
160+
141161
render() {
142162
const {
143163
openDrawer,
@@ -168,22 +188,21 @@ class SpaceHeader extends Component {
168188
{name}
169189
<span style={{ position: 'absolute', right: 20 }}>
170190
{this.renderClearButton()}
171-
{this.renderSyncButton()}
172191
{this.renderPreviewIcon()}
173-
{this.renderDeleteButton()}
174192
{this.renderExportButton()}
175-
{this.renderSaveButton()}
193+
{this.renderTeacherButtons()}
176194
</span>
177195
</Toolbar>
178196
</AppBar>
179197
);
180198
}
181199
}
182200

183-
const mapStateToProps = ({ Space }) => ({
201+
const mapStateToProps = ({ Space, authentication }) => ({
184202
space: Space.get('current')
185203
.get('content')
186204
.toJS(),
205+
studentMode: authentication.getIn(['user', 'settings', 'studentMode']),
187206
});
188207

189208
const mapDispatchToProps = {

0 commit comments

Comments
 (0)