2020-07-01 00:11:48 +02:00
|
|
|
import React from 'react';
|
2020-06-23 02:06:40 +02:00
|
|
|
import { bindActionCreators } from 'redux';
|
2020-07-17 21:06:13 +02:00
|
|
|
import { connect, useSelector, useDispatch } from 'react-redux';
|
2020-07-01 00:11:48 +02:00
|
|
|
import { withRouter } from 'react-router';
|
2020-06-23 02:06:40 +02:00
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import styled from 'styled-components';
|
2020-06-23 20:54:09 +02:00
|
|
|
|
|
|
|
import * as PreferencesActions from '../IDE/actions/preferences';
|
|
|
|
import * as IdeActions from '../IDE/actions/ide';
|
|
|
|
|
2020-07-01 00:11:48 +02:00
|
|
|
import IconButton from '../../components/mobile/IconButton';
|
2020-06-23 02:06:40 +02:00
|
|
|
import Screen from '../../components/mobile/MobileScreen';
|
|
|
|
import Header from '../../components/mobile/Header';
|
2020-06-30 21:52:03 +02:00
|
|
|
import PreferencePicker from '../../components/mobile/PreferencePicker';
|
2020-06-23 02:06:40 +02:00
|
|
|
import { ExitIcon } from '../../common/icons';
|
2020-06-23 22:03:51 +02:00
|
|
|
import { remSize, prop } from '../../theme';
|
2020-07-21 23:18:19 +02:00
|
|
|
import { optionsOnOff, optionsPickOne, preferenceOnOff } from '../IDE/components/Preferences/PreferenceCreators';
|
2020-06-23 02:06:40 +02:00
|
|
|
|
|
|
|
const Content = styled.div`
|
|
|
|
z-index: 0;
|
|
|
|
margin-top: ${remSize(68)};
|
|
|
|
`;
|
|
|
|
|
2020-06-23 22:03:51 +02:00
|
|
|
const SectionHeader = styled.h2`
|
|
|
|
color: ${prop('primaryTextColor')};
|
2020-07-01 21:44:19 +02:00
|
|
|
padding-top: ${remSize(32)};
|
2020-07-01 00:11:48 +02:00
|
|
|
`;
|
|
|
|
|
|
|
|
const SectionSubeader = styled.h3`
|
|
|
|
color: ${prop('primaryTextColor')};
|
2020-06-23 22:03:51 +02:00
|
|
|
`;
|
|
|
|
|
2020-06-23 02:06:40 +02:00
|
|
|
|
2020-07-17 21:06:13 +02:00
|
|
|
const MobilePreferences = () => {
|
|
|
|
// Props
|
2020-06-23 22:15:59 +02:00
|
|
|
const {
|
2020-07-17 21:06:13 +02:00
|
|
|
theme, autosave, linewrap, textOutput, gridOutput, soundOutput, lineNumbers, lintWarning
|
|
|
|
} = useSelector(state => state.preferences);
|
|
|
|
|
|
|
|
// Actions
|
2020-06-23 22:15:59 +02:00
|
|
|
const {
|
2020-07-17 21:06:13 +02:00
|
|
|
setTheme, setAutosave, setLinewrap, setTextOutput, setGridOutput, setSoundOutput, setLineNumbers, setLintWarning,
|
|
|
|
} = bindActionCreators({ ...PreferencesActions, ...IdeActions }, useDispatch());
|
|
|
|
|
2020-06-23 20:54:09 +02:00
|
|
|
|
2020-06-23 22:03:51 +02:00
|
|
|
const generalSettings = [
|
2020-06-23 02:06:40 +02:00
|
|
|
{
|
|
|
|
title: 'Theme',
|
2020-06-23 20:54:09 +02:00
|
|
|
value: theme,
|
2020-07-03 20:22:20 +02:00
|
|
|
options: optionsPickOne('theme', 'light', 'dark', 'contrast'),
|
2020-06-23 20:54:09 +02:00
|
|
|
onSelect: x => setTheme(x) // setTheme
|
2020-06-23 02:06:40 +02:00
|
|
|
},
|
2020-07-17 21:01:12 +02:00
|
|
|
preferenceOnOff('Autosave', autosave, setAutosave, 'autosave'),
|
|
|
|
preferenceOnOff('Word Wrap', linewrap, setLinewrap, 'linewrap')
|
2020-06-23 02:06:40 +02:00
|
|
|
];
|
|
|
|
|
2020-06-23 22:27:43 +02:00
|
|
|
const outputSettings = [
|
2020-07-17 21:01:12 +02: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 22:15:59 +02:00
|
|
|
];
|
|
|
|
|
2020-06-23 22:27:43 +02:00
|
|
|
const accessibilitySettings = [
|
2020-07-17 21:01:12 +02:00
|
|
|
preferenceOnOff('Line Numbers', lineNumbers, setLineNumbers),
|
|
|
|
preferenceOnOff('Lint Warning Sound', lintWarning, setLintWarning)
|
2020-06-23 22:27:43 +02:00
|
|
|
];
|
|
|
|
|
2020-06-23 02:06:40 +02:00
|
|
|
return (
|
2020-06-23 21:18:34 +02:00
|
|
|
<Screen fullscreen>
|
|
|
|
<section>
|
2020-07-03 20:22:20 +02:00
|
|
|
<Header transparent title="Preferences">
|
2020-08-19 23:30:11 +02:00
|
|
|
<IconButton to="/" icon={ExitIcon} aria-label="Return to ide view" />
|
2020-07-03 20:22:20 +02:00
|
|
|
</Header>
|
2020-06-23 21:18:34 +02:00
|
|
|
<section className="preferences">
|
|
|
|
<Content>
|
2020-06-23 22:03:51 +02:00
|
|
|
<SectionHeader>General Settings</SectionHeader>
|
2020-06-30 21:52:03 +02:00
|
|
|
{ generalSettings.map(option => <PreferencePicker key={`${option.title}wrapper`} {...option} />) }
|
2020-06-23 22:03:51 +02:00
|
|
|
|
|
|
|
<SectionHeader>Accessibility</SectionHeader>
|
2020-06-30 21:52:03 +02:00
|
|
|
{ accessibilitySettings.map(option => <PreferencePicker key={`${option.title}wrapper`} {...option} />) }
|
2020-06-23 22:15:59 +02:00
|
|
|
|
2020-06-23 22:27:43 +02:00
|
|
|
<SectionHeader>Accessible Output</SectionHeader>
|
2020-07-01 00:11:48 +02:00
|
|
|
<SectionSubeader>Used with screen reader</SectionSubeader>
|
2020-06-30 21:52:03 +02:00
|
|
|
{ outputSettings.map(option => <PreferencePicker key={`${option.title}wrapper`} {...option} />) }
|
2020-06-23 22:27:43 +02:00
|
|
|
|
2020-06-23 21:18:34 +02:00
|
|
|
</Content>
|
|
|
|
</section>
|
2020-06-23 02:06:40 +02:00
|
|
|
</section>
|
|
|
|
</Screen>);
|
|
|
|
};
|
|
|
|
|
2020-07-17 21:06:13 +02:00
|
|
|
export default withRouter(MobilePreferences);
|