2020-06-30 22:11:48 +00:00
|
|
|
import React from 'react';
|
2020-06-23 00:06:40 +00:00
|
|
|
import { bindActionCreators } from 'redux';
|
|
|
|
import { connect } from 'react-redux';
|
2020-06-30 22:11:48 +00:00
|
|
|
import { withRouter } from 'react-router';
|
2020-06-23 00:06:40 +00:00
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import styled from 'styled-components';
|
2020-06-23 18:54:09 +00:00
|
|
|
|
|
|
|
import * as PreferencesActions from '../IDE/actions/preferences';
|
|
|
|
import * as IdeActions from '../IDE/actions/ide';
|
|
|
|
|
2020-06-30 22:11:48 +00:00
|
|
|
import IconButton from '../../components/mobile/IconButton';
|
2020-06-23 00:06:40 +00:00
|
|
|
import Screen from '../../components/mobile/MobileScreen';
|
|
|
|
import Header from '../../components/mobile/Header';
|
2020-06-30 19:52:03 +00:00
|
|
|
import PreferencePicker from '../../components/mobile/PreferencePicker';
|
2020-06-23 00:06:40 +00:00
|
|
|
import { ExitIcon } from '../../common/icons';
|
2020-06-23 20:03:51 +00:00
|
|
|
import { remSize, prop } from '../../theme';
|
2020-06-23 00:06:40 +00:00
|
|
|
|
|
|
|
const Content = styled.div`
|
|
|
|
z-index: 0;
|
|
|
|
margin-top: ${remSize(68)};
|
|
|
|
`;
|
|
|
|
|
2020-06-23 20:03:51 +00:00
|
|
|
const SectionHeader = styled.h2`
|
|
|
|
color: ${prop('primaryTextColor')};
|
2020-07-01 19:44:19 +00:00
|
|
|
padding-top: ${remSize(32)};
|
2020-06-30 22:11:48 +00:00
|
|
|
`;
|
|
|
|
|
|
|
|
const SectionSubeader = styled.h3`
|
|
|
|
color: ${prop('primaryTextColor')};
|
2020-06-23 20:03:51 +00:00
|
|
|
`;
|
|
|
|
|
2020-07-03 18:22:20 +00:00
|
|
|
const optionsOnOff = (name, onLabel = 'On', offLabel = 'Off') => [
|
|
|
|
{
|
|
|
|
value: true, label: onLabel, ariaLabel: `${name} on`, name: `${name}`, id: `${name}-on`.replace(' ', '-')
|
|
|
|
},
|
|
|
|
{
|
|
|
|
value: false, label: offLabel, ariaLabel: `${name} off`, name: `${name}`, id: `${name}-off`.replace(' ', '-')
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
const optionsPickOne = (name, ...options) => options.map(option => ({
|
|
|
|
value: option,
|
|
|
|
label: option,
|
|
|
|
ariaLabel: `${option} ${name} on`,
|
|
|
|
name: `${option} ${name}`,
|
|
|
|
id: `${option}-${name}-on`.replace(' ', '-')
|
|
|
|
}));
|
|
|
|
|
2020-06-23 00:06:40 +00:00
|
|
|
|
|
|
|
const MobilePreferences = (props) => {
|
2020-06-23 20:15:59 +00:00
|
|
|
const {
|
2020-06-23 20:27:43 +00:00
|
|
|
setTheme, setAutosave, setLinewrap, setTextOutput, setGridOutput, setSoundOutput, lineNumbers, lintWarning
|
2020-06-23 20:15:59 +00:00
|
|
|
} = props;
|
|
|
|
const {
|
2020-06-23 20:27:43 +00:00
|
|
|
theme, autosave, linewrap, textOutput, gridOutput, soundOutput, setLineNumbers, setLintWarning
|
2020-06-23 20:15:59 +00:00
|
|
|
} = props;
|
2020-06-23 18:54:09 +00:00
|
|
|
|
2020-06-23 20:03:51 +00:00
|
|
|
const generalSettings = [
|
2020-06-23 00:06:40 +00:00
|
|
|
{
|
|
|
|
title: 'Theme',
|
2020-06-23 18:54:09 +00:00
|
|
|
value: theme,
|
2020-07-03 18:22:20 +00:00
|
|
|
options: optionsPickOne('theme', 'light', 'dark', 'contrast'),
|
2020-06-23 18:54:09 +00:00
|
|
|
onSelect: x => setTheme(x) // setTheme
|
2020-06-23 00:06:40 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
title: 'Autosave',
|
2020-06-23 18:54:09 +00:00
|
|
|
value: autosave,
|
2020-07-03 18:22:20 +00:00
|
|
|
options: optionsOnOff('autosave'),
|
2020-06-23 18:54:09 +00:00
|
|
|
onSelect: x => setAutosave(x) // setAutosave
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
title: 'Word Wrap',
|
|
|
|
value: linewrap,
|
2020-07-03 18:22:20 +00:00
|
|
|
options: optionsOnOff('linewrap'),
|
2020-06-23 18:54:09 +00:00
|
|
|
onSelect: x => setLinewrap(x)
|
2020-06-23 00:06:40 +00:00
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2020-06-23 20:27:43 +00:00
|
|
|
const outputSettings = [
|
2020-06-23 20:15:59 +00:00
|
|
|
{
|
|
|
|
title: 'Plain-text',
|
|
|
|
value: textOutput,
|
2020-07-03 18:22:20 +00:00
|
|
|
options: optionsOnOff('text output'),
|
2020-06-23 20:15:59 +00:00
|
|
|
onSelect: x => setTextOutput(x)
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Table-text',
|
|
|
|
value: gridOutput,
|
2020-07-03 18:22:20 +00:00
|
|
|
options: optionsOnOff('table output'),
|
2020-06-23 20:15:59 +00:00
|
|
|
onSelect: x => setGridOutput(x)
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Sound',
|
|
|
|
value: soundOutput,
|
2020-07-03 18:22:20 +00:00
|
|
|
options: optionsOnOff('sound output'),
|
2020-06-23 20:15:59 +00:00
|
|
|
onSelect: x => setSoundOutput(x)
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
2020-06-23 20:27:43 +00:00
|
|
|
const accessibilitySettings = [
|
|
|
|
{
|
|
|
|
title: 'Line Numbers',
|
|
|
|
value: lineNumbers,
|
2020-07-03 18:22:20 +00:00
|
|
|
options: optionsOnOff('line numbers'),
|
2020-06-23 20:27:43 +00:00
|
|
|
onSelect: x => setLineNumbers(x)
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Lint Warning Sound',
|
|
|
|
value: lintWarning,
|
2020-07-03 18:22:20 +00:00
|
|
|
options: optionsOnOff('lint warning'),
|
2020-06-23 20:27:43 +00:00
|
|
|
onSelect: x => setLintWarning(x)
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
2020-06-23 00:06:40 +00:00
|
|
|
return (
|
2020-06-23 19:18:34 +00:00
|
|
|
<Screen fullscreen>
|
|
|
|
<section>
|
2020-07-03 18:22:20 +00:00
|
|
|
<Header transparent title="Preferences">
|
2020-07-01 19:44:19 +00:00
|
|
|
<IconButton to="/mobile" icon={ExitIcon} aria-label="Return to ide view" />
|
2020-07-03 18:22:20 +00:00
|
|
|
</Header>
|
2020-06-23 19:18:34 +00:00
|
|
|
<section className="preferences">
|
|
|
|
<Content>
|
2020-06-23 20:03:51 +00:00
|
|
|
<SectionHeader>General Settings</SectionHeader>
|
2020-06-30 19:52:03 +00:00
|
|
|
{ generalSettings.map(option => <PreferencePicker key={`${option.title}wrapper`} {...option} />) }
|
2020-06-23 20:03:51 +00:00
|
|
|
|
|
|
|
<SectionHeader>Accessibility</SectionHeader>
|
2020-06-30 19:52:03 +00:00
|
|
|
{ accessibilitySettings.map(option => <PreferencePicker key={`${option.title}wrapper`} {...option} />) }
|
2020-06-23 20:15:59 +00:00
|
|
|
|
2020-06-23 20:27:43 +00:00
|
|
|
<SectionHeader>Accessible Output</SectionHeader>
|
2020-06-30 22:11:48 +00:00
|
|
|
<SectionSubeader>Used with screen reader</SectionSubeader>
|
2020-06-30 19:52:03 +00:00
|
|
|
{ outputSettings.map(option => <PreferencePicker key={`${option.title}wrapper`} {...option} />) }
|
2020-06-23 20:27:43 +00:00
|
|
|
|
2020-06-23 19:18:34 +00:00
|
|
|
</Content>
|
|
|
|
</section>
|
2020-06-23 00:06:40 +00:00
|
|
|
</section>
|
|
|
|
</Screen>);
|
|
|
|
};
|
|
|
|
|
2020-06-23 20:27:43 +00:00
|
|
|
|
2020-06-23 00:06:40 +00:00
|
|
|
MobilePreferences.propTypes = {
|
|
|
|
fontSize: PropTypes.number.isRequired,
|
|
|
|
lineNumbers: PropTypes.bool.isRequired,
|
|
|
|
autosave: PropTypes.bool.isRequired,
|
|
|
|
linewrap: PropTypes.bool.isRequired,
|
|
|
|
textOutput: PropTypes.bool.isRequired,
|
|
|
|
gridOutput: PropTypes.bool.isRequired,
|
|
|
|
soundOutput: PropTypes.bool.isRequired,
|
|
|
|
lintWarning: PropTypes.bool.isRequired,
|
|
|
|
theme: PropTypes.string.isRequired,
|
|
|
|
|
|
|
|
setLinewrap: PropTypes.func.isRequired,
|
|
|
|
setLintWarning: PropTypes.func.isRequired,
|
|
|
|
setTheme: PropTypes.func.isRequired,
|
|
|
|
setFontSize: PropTypes.func.isRequired,
|
|
|
|
setLineNumbers: PropTypes.func.isRequired,
|
|
|
|
setAutosave: PropTypes.func.isRequired,
|
|
|
|
setTextOutput: PropTypes.func.isRequired,
|
|
|
|
setGridOutput: PropTypes.func.isRequired,
|
|
|
|
setSoundOutput: PropTypes.func.isRequired,
|
|
|
|
};
|
|
|
|
|
|
|
|
const mapStateToProps = state => ({
|
2020-06-23 18:54:09 +00:00
|
|
|
...state.preferences,
|
2020-06-23 00:06:40 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
const mapDispatchToProps = dispatch => bindActionCreators({
|
|
|
|
...PreferencesActions,
|
|
|
|
...IdeActions
|
|
|
|
}, dispatch);
|
|
|
|
|
|
|
|
|
2020-06-23 18:54:09 +00:00
|
|
|
export default withRouter(connect(mapStateToProps, mapDispatchToProps)(MobilePreferences));
|