Skip to content

Commit 2e20609

Browse files
committed
feat: add switch for action enabled and action access
1 parent d498c97 commit 2e20609

22 files changed

+460
-88
lines changed

public/app/config/channels.js

+2
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ module.exports = {
5252
SET_USER_MODE_CHANNEL: 'user:mode:set',
5353
SET_SPACE_AS_FAVORITE_CHANNEL: 'user:set-space-favorite:set',
5454
SET_SPACE_AS_RECENT_CHANNEL: 'user:set-space-recent:set',
55+
SET_ACTION_ACCESSIBILITY_CHANNEL: 'user:action:accessibility:set',
56+
SET_ACTION_ENABLED_CHANNEL: 'user:action:enabled:set',
5557
GET_CLASSROOMS_CHANNEL: 'classrooms:get',
5658
ADD_CLASSROOM_CHANNEL: 'classroom:add',
5759
DELETE_CLASSROOM_CHANNEL: 'classroom:delete',

public/app/config/config.js

+4
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ const DEFAULT_PROTOCOL = 'https';
5252
const DEFAULT_LOGGING_LEVEL = 'info';
5353
const AUTHENTICATED = 'authenticated';
5454
const DEFAULT_AUTHENTICATION = false;
55+
const DEFAULT_ACTION_ACCESSIBILITY = false;
56+
const DEFAULT_ACTION_ENABLED = true;
5557

5658
const DEFAULT_USER = {
5759
geolocation: null,
@@ -61,6 +63,8 @@ const DEFAULT_USER = {
6163
geolocationEnabled: DEFAULT_GEOLOCATION_ENABLED,
6264
syncMode: DEFAULT_SYNC_MODE,
6365
userMode: DEFAULT_USER_MODE,
66+
actionAccessibility: DEFAULT_ACTION_ACCESSIBILITY,
67+
actionEnabled: DEFAULT_ACTION_ENABLED,
6468
},
6569
favoriteSpaces: [],
6670
recentSpaces: [],

public/app/config/messages.js

+6
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,10 @@ const ERROR_INVALID_USERNAME_MESSAGE = 'This username is invalid';
9999
const ERROR_NO_USER_TO_DELETE_MESSAGE = 'There is no user to delete';
100100
const ERROR_GETTING_SPACE_IN_CLASSROOM_MESSAGE =
101101
'There was an error getting the space in this classroom';
102+
const ERROR_SETTING_ACTION_ACCESSIBILITY =
103+
'There was an error setting the action accessibility';
104+
const ERROR_SETTING_ACTION_ENABLED =
105+
'There was an error setting the action enabled';
102106

103107
module.exports = {
104108
ERROR_GETTING_DEVELOPER_MODE,
@@ -167,4 +171,6 @@ module.exports = {
167171
ERROR_NO_USER_TO_DELETE_MESSAGE,
168172
ERROR_GETTING_SPACE_IN_CLASSROOM_MESSAGE,
169173
ERROR_INVALID_USERNAME_MESSAGE,
174+
ERROR_SETTING_ACTION_ACCESSIBILITY,
175+
ERROR_SETTING_ACTION_ENABLED,
170176
};

public/app/listeners/index.js

+4
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ const deleteUsersInClassroom = require('./deleteUsersInClassroom');
4747
const editUserInClassroom = require('./editUserInClassroom');
4848
const getSpaceInClassroom = require('./getSpaceInClassroom');
4949
const loadSpaceInClassroom = require('./loadSpaceInClassroom');
50+
const setActionAccessibility = require('./setActionAccessibility');
51+
const setActionEnabled = require('./setActionEnabled');
5052

5153
module.exports = {
5254
loadSpace,
@@ -97,4 +99,6 @@ module.exports = {
9799
editUserInClassroom,
98100
getSpaceInClassroom,
99101
loadSpaceInClassroom,
102+
setActionAccessibility,
103+
setActionEnabled,
100104
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
const { SET_ACTION_ACCESSIBILITY_CHANNEL } = require('../config/channels');
2+
const { ERROR_GENERAL } = require('../config/errors');
3+
const logger = require('../logger');
4+
5+
const setActionAccessibility = (mainWindow, db) => async (
6+
event,
7+
actionAccessibility
8+
) => {
9+
try {
10+
db.set('user.settings.actionAccessibility', actionAccessibility).write();
11+
mainWindow.webContents.send(
12+
SET_ACTION_ACCESSIBILITY_CHANNEL,
13+
actionAccessibility
14+
);
15+
} catch (e) {
16+
logger.error(e);
17+
mainWindow.webContents.send(
18+
SET_ACTION_ACCESSIBILITY_CHANNEL,
19+
ERROR_GENERAL
20+
);
21+
}
22+
};
23+
24+
module.exports = setActionAccessibility;
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
const { SET_ACTION_ENABLED_CHANNEL } = require('../config/channels');
2+
const { ERROR_GENERAL } = require('../config/errors');
3+
const { DEFAULT_ACTION_ENABLED } = require('../config/config');
4+
const logger = require('../logger');
5+
6+
const setActionEnabled = (mainWindow, db) => async (event, actionEnabled) => {
7+
try {
8+
db.set('user.settings.actionEnabled', actionEnabled).write();
9+
mainWindow.webContents.send(
10+
SET_ACTION_ENABLED_CHANNEL,
11+
actionEnabled || DEFAULT_ACTION_ENABLED
12+
);
13+
} catch (e) {
14+
logger.error(e);
15+
mainWindow.webContents.send(SET_ACTION_ENABLED_CHANNEL, ERROR_GENERAL);
16+
}
17+
};
18+
19+
module.exports = setActionEnabled;

public/electron.js

+13
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ const {
7272
EDIT_USER_IN_CLASSROOM_CHANNEL,
7373
GET_SPACE_IN_CLASSROOM_CHANNEL,
7474
LOAD_SPACE_IN_CLASSROOM_CHANNEL,
75+
SET_ACTION_ACCESSIBILITY_CHANNEL,
76+
SET_ACTION_ENABLED_CHANNEL,
7577
} = require('./app/config/channels');
7678
const env = require('./env.json');
7779
const {
@@ -122,6 +124,8 @@ const {
122124
editUserInClassroom,
123125
getSpaceInClassroom,
124126
loadSpaceInClassroom,
127+
setActionAccessibility,
128+
setActionEnabled,
125129
} = require('./app/listeners');
126130
const isMac = require('./app/utils/isMac');
127131

@@ -463,6 +467,15 @@ app.on('ready', async () => {
463467
setGeolocationEnabled(mainWindow, db)
464468
);
465469

470+
// called when setting action accessibility
471+
ipcMain.on(
472+
SET_ACTION_ACCESSIBILITY_CHANNEL,
473+
setActionAccessibility(mainWindow, db)
474+
);
475+
476+
// called when setting action enabled
477+
ipcMain.on(SET_ACTION_ENABLED_CHANNEL, setActionEnabled(mainWindow, db));
478+
466479
// called when getting student mode
467480
ipcMain.on(GET_USER_MODE_CHANNEL, getUserMode(mainWindow, db));
468481

src/actions/user.js

+62
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ import {
2828
SET_SPACE_AS_FAVORITE_SUCCEEDED,
2929
FLAG_SETTING_SPACE_AS_RECENT,
3030
SET_SPACE_AS_RECENT_SPACES_SUCCEEDED,
31+
FLAG_SETTING_ACTION_ACCESSIBILITY,
32+
SET_ACTION_ACCESSIBILITY_SUCCEEDED,
33+
FLAG_SETTING_ACTION_ENABLED,
34+
SET_ACTION_ENABLED_SUCCEEDED,
3135
} from '../types';
3236
import {
3337
ERROR_GETTING_GEOLOCATION,
@@ -45,6 +49,8 @@ import {
4549
ERROR_SETTING_USER_MODE,
4650
ERROR_SETTING_SPACE_AS_FAVORITE,
4751
ERROR_SETTING_SPACE_AS_RECENT,
52+
ERROR_SETTING_ACTION_ACCESSIBILITY,
53+
ERROR_SETTING_ACTION_ENABLED,
4854
} from '../config/messages';
4955
import {
5056
GET_USER_FOLDER_CHANNEL,
@@ -60,6 +66,8 @@ import {
6066
SET_USER_MODE_CHANNEL,
6167
SET_SPACE_AS_FAVORITE_CHANNEL,
6268
SET_SPACE_AS_RECENT_CHANNEL,
69+
SET_ACTION_ACCESSIBILITY_CHANNEL,
70+
SET_ACTION_ENABLED_CHANNEL,
6371
} from '../config/channels';
6472
import { createFlag } from './common';
6573
import { ERROR_GENERAL } from '../config/errors';
@@ -81,6 +89,10 @@ const flagGettingUserMode = createFlag(FLAG_GETTING_USER_MODE);
8189
const flagSettingUserMode = createFlag(FLAG_SETTING_USER_MODE);
8290
const flagSettingSpaceAsFavorite = createFlag(FLAG_SETTING_SPACE_AS_FAVORITE);
8391
const flagSettingSpaceAsRecent = createFlag(FLAG_SETTING_SPACE_AS_RECENT);
92+
const flagSettingActionAccessibility = createFlag(
93+
FLAG_SETTING_ACTION_ACCESSIBILITY
94+
);
95+
const flagSettingActionEnabled = createFlag(FLAG_SETTING_ACTION_ENABLED);
8496

8597
const getGeolocation = async () => async dispatch => {
8698
// only fetch location if online
@@ -399,6 +411,54 @@ const setSpaceAsRecent = payload => dispatch => {
399411
}
400412
};
401413

414+
const setActionAccessibility = payload => dispatch => {
415+
try {
416+
dispatch(flagSettingActionAccessibility(true));
417+
window.ipcRenderer.send(SET_ACTION_ACCESSIBILITY_CHANNEL, payload);
418+
window.ipcRenderer.once(
419+
SET_ACTION_ACCESSIBILITY_CHANNEL,
420+
(event, response) => {
421+
if (response === ERROR_GENERAL) {
422+
toastr.error(
423+
ERROR_MESSAGE_HEADER,
424+
ERROR_SETTING_ACTION_ACCESSIBILITY
425+
);
426+
} else {
427+
dispatch({
428+
type: SET_ACTION_ACCESSIBILITY_SUCCEEDED,
429+
payload,
430+
});
431+
}
432+
dispatch(flagSettingActionAccessibility(false));
433+
}
434+
);
435+
} catch (e) {
436+
console.error(e);
437+
toastr.error(ERROR_MESSAGE_HEADER, ERROR_SETTING_ACTION_ACCESSIBILITY);
438+
}
439+
};
440+
441+
const setActionEnabled = payload => dispatch => {
442+
try {
443+
dispatch(flagSettingActionEnabled(true));
444+
window.ipcRenderer.send(SET_ACTION_ENABLED_CHANNEL, payload);
445+
window.ipcRenderer.once(SET_ACTION_ENABLED_CHANNEL, (event, response) => {
446+
if (response === ERROR_GENERAL) {
447+
toastr.error(ERROR_MESSAGE_HEADER, ERROR_SETTING_ACTION_ENABLED);
448+
} else {
449+
dispatch({
450+
type: SET_ACTION_ENABLED_SUCCEEDED,
451+
payload,
452+
});
453+
}
454+
dispatch(flagSettingActionEnabled(false));
455+
});
456+
} catch (e) {
457+
console.error(e);
458+
toastr.error(ERROR_MESSAGE_HEADER, ERROR_SETTING_ACTION_ENABLED);
459+
}
460+
};
461+
402462
export {
403463
getUserFolder,
404464
getGeolocation,
@@ -414,4 +474,6 @@ export {
414474
setUserMode,
415475
setSpaceAsFavorite,
416476
setSpaceAsRecent,
477+
setActionAccessibility,
478+
setActionEnabled,
417479
};

src/components/Settings.js

+21-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import Typography from '@material-ui/core/Typography';
66
import { connect } from 'react-redux';
77
import { FormGroup } from '@material-ui/core';
88
import { withTranslation } from 'react-i18next';
9+
import Divider from '@material-ui/core/Divider';
910
import Styles from '../Styles';
1011
import LanguageSelect from './common/LanguageSelect';
1112
import DeveloperSwitch from './common/DeveloperSwitch';
@@ -14,8 +15,17 @@ import Main from './common/Main';
1415
import { SETTINGS_MAIN_ID } from '../config/selectors';
1516
import SyncAdvancedSwitch from './space/sync/SyncAdvancedSwitch';
1617
import StudentModeSwitch from './common/StudentModeSwitch';
18+
import ActionEnabledSwitch from './common/ActionEnabledSwitch';
19+
import ActionAccessibilitySwitch from './common/ActionAccessibilitySwitch';
1720
import { USER_MODES } from '../config/constants';
1821

22+
const styles = theme => ({
23+
...Styles(theme),
24+
divider: {
25+
margin: theme.spacing(2, 0),
26+
},
27+
});
28+
1929
// eslint-disable-next-line react/prefer-stateless-function
2030
export class Settings extends Component {
2131
static propTypes = {
@@ -27,6 +37,7 @@ export class Settings extends Component {
2737
content: PropTypes.string.isRequired,
2838
contentShift: PropTypes.string.isRequired,
2939
settings: PropTypes.string.isRequired,
40+
divider: PropTypes.string.isRequired,
3041
}).isRequired,
3142
i18n: PropTypes.shape({
3243
changeLanguage: PropTypes.func.isRequired,
@@ -40,7 +51,7 @@ export class Settings extends Component {
4051
return (
4152
<Main id={SETTINGS_MAIN_ID}>
4253
<div className={classes.settings}>
43-
<Typography variant="h5" color="inherit">
54+
<Typography variant="h4" color="inherit">
4455
{t('Settings')}
4556
</Typography>
4657
<FormGroup>
@@ -50,6 +61,14 @@ export class Settings extends Component {
5061
<StudentModeSwitch />
5162
{userMode === USER_MODES.TEACHER ? <DeveloperSwitch /> : null}
5263
</FormGroup>
64+
<Divider variant="middle" classes={{ root: classes.divider }} />
65+
<Typography variant="h5" color="inherit" className="mt-2">
66+
{t('Actions')}
67+
</Typography>
68+
<FormGroup>
69+
<ActionEnabledSwitch />
70+
<ActionAccessibilitySwitch />
71+
</FormGroup>
5372
</div>
5473
</Main>
5574
);
@@ -62,7 +81,7 @@ const mapStateToProps = ({ authentication }) => ({
6281

6382
const ConnectedComponent = connect(mapStateToProps, null)(Settings);
6483

65-
const StyledComponent = withStyles(Styles, { withTheme: true })(
84+
const StyledComponent = withStyles(styles, { withTheme: true })(
6685
ConnectedComponent
6786
);
6887

src/components/Settings.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ describe('<Settings />', () => {
5050
});
5151

5252
it('renders one <Typography /> component with text Settings', () => {
53-
const typography = wrapper.find(Typography);
53+
const typography = wrapper.find(Typography).find({ variant: 'h4' });
5454
expect(typography).toHaveLength(1);
5555
expect(typography.contains('Settings')).toBeTruthy();
5656
});

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

+20-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ exports[`<Settings /> renders correctly 1`] = `
99
>
1010
<WithStyles(ForwardRef(Typography))
1111
color="inherit"
12-
variant="h5"
12+
variant="h4"
1313
>
1414
Settings
1515
</WithStyles(ForwardRef(Typography))>
@@ -20,6 +20,25 @@ exports[`<Settings /> renders correctly 1`] = `
2020
<withI18nextTranslation(WithStyles(Connect(StudentModeSwitch))) />
2121
<withI18nextTranslation(WithStyles(Connect(DeveloperSwitch))) />
2222
</WithStyles(ForwardRef(FormGroup))>
23+
<WithStyles(ForwardRef(Divider))
24+
classes={
25+
Object {
26+
"root": undefined,
27+
}
28+
}
29+
variant="middle"
30+
/>
31+
<WithStyles(ForwardRef(Typography))
32+
className="mt-2"
33+
color="inherit"
34+
variant="h5"
35+
>
36+
Actions
37+
</WithStyles(ForwardRef(Typography))>
38+
<WithStyles(ForwardRef(FormGroup))>
39+
<withI18nextTranslation(WithStyles(Connect(ActionEnabledSwitch))) />
40+
<withI18nextTranslation(WithStyles(Connect(ActionAccessibilitySwitch))) />
41+
</WithStyles(ForwardRef(FormGroup))>
2342
</div>
2443
</withI18nextTranslation(WithStyles(Connect(Main)))>
2544
`;

0 commit comments

Comments
 (0)