2020-06-30 22:11:48 +00:00
|
|
|
import React from 'react';
|
2020-06-23 00:06:40 +00:00
|
|
|
import { bindActionCreators } from 'redux';
|
2020-07-17 19:06:13 +00:00
|
|
|
import { connect, useSelector, useDispatch } 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-07-17 19:01:12 +00:00
|
|
|
import { optionsOnOff, optionsPickOne, preferenceOnOff } from '../../common/helpers/PreferenceCreators';
|
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-06-23 00:06:40 +00:00
|
|
|
|
2020-07-17 19:06:13 +00:00
|
|
|
const MobilePreferences = () => {
|
|
|
|
// Props
|
2020-06-23 20:15:59 +00:00
|
|
|
const {
|
2020-07-17 19:06:13 +00:00
|
|
|
theme, autosave, linewrap, textOutput, gridOutput, soundOutput, lineNumbers, lintWarning
|
|
|
|
} = useSelector(state => state.preferences);
|
|
|
|
|
|
|
|
// Actions
|
2020-06-23 20:15:59 +00:00
|
|
|
const {
|
2020-07-17 19:06:13 +00:00
|
|
|
setTheme, setAutosave, setLinewrap, setTextOutput, setGridOutput, setSoundOutput, setLineNumbers, setLintWarning,
|
|
|
|
} = bindActionCreators({ ...PreferencesActions, ...IdeActions }, useDispatch());
|
|
|
|
|
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
|
|
|
},
|
2020-07-17 19:01:12 +00:00
|
|
|
preferenceOnOff('Autosave', autosave, setAutosave, 'autosave'),
|
|
|
|
preferenceOnOff('Word Wrap', linewrap, setLinewrap, 'linewrap')
|
2020-06-23 00:06:40 +00:00
|
|
|
];
|
|
|
|
|
2020-06-23 20:27:43 +00:00
|
|
|
const outputSettings = [
|
2020-07-17 19:01:12 +00:00
|
|
|
preferenceOnOff('Plain-text', textOutput, setTextOutput, 'text output'),
|
|
|
|
preferenceOnOff('Table-text', gridOutput, setGridOutput, 'table output'),
|
|
|
|
preferenceOnOff('Lint Warning Sound', soundOutput, setSoundOutput, 'sound output')
|
2020-06-23 20:15:59 +00:00
|
|
|
];
|
|
|
|
|
2020-06-23 20:27:43 +00:00
|
|
|
const accessibilitySettings = [
|
2020-07-17 19:01:12 +00:00
|
|
|
preferenceOnOff('Line Numbers', lineNumbers, setLineNumbers),
|
|
|
|
preferenceOnOff('Lint Warning Sound', lintWarning, setLintWarning)
|
2020-06-23 20:27:43 +00:00
|
|
|
];
|
|
|
|
|
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,
|
|
|
|
};
|
|
|
|
|
2020-07-17 19:06:13 +00:00
|
|
|
export default withRouter(MobilePreferences);
|