1
1
import React , { useEffect } from 'react' ;
2
2
import { bindActionCreators } from 'redux' ;
3
3
import { connect } from 'react-redux' ;
4
- import { Link } from 'react-router' ;
4
+ import { Link , withRouter } from 'react-router' ;
5
5
import PropTypes from 'prop-types' ;
6
6
import styled from 'styled-components' ;
7
+
8
+ import * as PreferencesActions from '../IDE/actions/preferences' ;
9
+ import * as IdeActions from '../IDE/actions/ide' ;
10
+
7
11
import Screen from '../../components/mobile/MobileScreen' ;
8
12
import Header from '../../components/mobile/Header' ;
9
13
import { ExitIcon } from '../../common/icons' ;
10
14
import { remSize } from '../../theme' ;
11
- import * as PreferencesActions from '../IDE/actions/preferences' ;
12
- import * as IdeActions from '../IDE/actions/ide' ;
13
15
14
16
const IconLinkWrapper = styled ( Link ) `
15
17
width: 3rem;
@@ -22,57 +24,25 @@ const Content = styled.div`
22
24
margin-top: ${ remSize ( 68 ) } ;
23
25
` ;
24
26
25
- /*
26
- <div className="preference">
27
- <h4 className="preference__title">Word Wrap</h4>
28
- <div className="preference__options">
29
- <input
30
- type="radio"
31
- onChange={() => this.props.setLinewrap(true)}
32
- aria-label="linewrap on"
33
- name="linewrap"
34
- id="linewrap-on"
35
- className="preference__radio-button"
36
- value="On"
37
- checked={this.props.linewrap}
38
- />
39
- <label htmlFor="linewrap-on" className="preference__option">On</label>
40
- <input
41
- type="radio"
42
- onChange={() => this.props.setLinewrap(false)}
43
- aria-label="linewrap off"
44
- name="linewrap"
45
- id="linewrap-off"
46
- className="preference__radio-button"
47
- value="Off"
48
- checked={!this.props.linewrap}
49
- />
50
- <label htmlFor="linewrap-off" className="preference__option">Off</label>
51
- </div>
52
- </div>
53
- */
54
-
55
27
const Selector = ( {
56
- title, value, onSelect, ariaLabel , name , id , options,
28
+ title, value, onSelect, options,
57
29
} ) => (
58
30
< div className = "preference" >
59
31
< h4 className = "preference__title" > { title } </ h4 >
60
32
{ options . map ( option => (
61
- < div className = "preference__options" >
33
+ < div className = "preference__options" key = { option . id } >
62
34
< input
63
35
type = "radio"
64
-
65
36
onChange = { ( ) => onSelect ( option . value ) }
66
- aria-label = { ariaLabel }
67
- name = { name }
68
- id = { id }
37
+ aria-label = { option . ariaLabel }
38
+ name = { option . name }
39
+ id = { option . id }
69
40
className = "preference__radio-button"
70
41
value = { option . value }
71
42
checked = { value === option . value }
72
43
/>
73
- < label htmlFor = { id } className = "preference__option" > { option . label } </ label >
44
+ < label htmlFor = { option . id } className = "preference__option" > { option . label } </ label >
74
45
</ div > ) ) }
75
-
76
46
</ div >
77
47
) ;
78
48
@@ -82,12 +52,14 @@ Selector.defaultProps = {
82
52
83
53
Selector . propTypes = {
84
54
title : PropTypes . string . isRequired ,
85
- value : PropTypes . string . isRequired ,
86
- options : PropTypes . arrayOf ( PropTypes . string ) ,
87
- ariaLabel : PropTypes . string . isRequired ,
88
- name : PropTypes . string . isRequired ,
89
- id : PropTypes . string . isRequired ,
90
- onSelect : PropTypes . string . isRequired ,
55
+ value : PropTypes . oneOfType ( [ PropTypes . bool , PropTypes . string ] ) . isRequired ,
56
+ options : PropTypes . arrayOf ( PropTypes . shape ( {
57
+ id : PropTypes . string ,
58
+ name : PropTypes . string ,
59
+ label : PropTypes . string ,
60
+ ariaLabel : PropTypes . string ,
61
+ } ) ) ,
62
+ onSelect : PropTypes . func . isRequired ,
91
63
} ;
92
64
93
65
const SettingsHeader = styled ( Header ) `
@@ -96,11 +68,13 @@ const SettingsHeader = styled(Header)`
96
68
97
69
98
70
const MobilePreferences = ( props ) => {
99
- const { setTheme } = props ;
71
+ const { setTheme, setAutosave, setLinewrap } = props ;
72
+ const { theme, autosave, linewrap } = props ;
73
+
100
74
const preferences = [
101
75
{
102
76
title : 'Theme' ,
103
- value : 'light' ,
77
+ value : theme ,
104
78
options : [
105
79
{
106
80
value : 'light' , label : 'light' , ariaLabel : 'light theme on' , name : 'light theme' , id : 'light-theme-on'
@@ -112,44 +86,55 @@ const MobilePreferences = (props) => {
112
86
value : 'contrast' , label : 'contrast' , ariaLabel : 'contrast theme on' , name : 'contrast theme' , id : 'contrast-theme-on'
113
87
}
114
88
] ,
115
- onSelect : setTheme // setTheme
89
+ onSelect : x => setTheme ( x ) // setTheme
116
90
} ,
117
91
118
92
{
119
93
title : 'Autosave' ,
120
- value : true ,
94
+ value : autosave ,
121
95
options : [
122
96
{
123
- value : 'On' , label : 'On' , ariaLabel : 'autosave on' , name : 'autosave' , id : 'autosave-on'
97
+ value : true , label : 'On' , ariaLabel : 'autosave on' , name : 'autosave' , id : 'autosave-on'
124
98
} ,
125
99
{
126
- value : 'Off' , label : 'Off' , ariaLabel : 'autosave off' , name : 'autosave' , id : 'autosave-off'
100
+ value : false , label : 'Off' , ariaLabel : 'autosave off' , name : 'autosave' , id : 'autosave-off'
127
101
} ,
128
102
] ,
129
- onSelect : ( ) => { } // setAutosave
103
+ onSelect : x => setAutosave ( x ) // setAutosave
104
+ } ,
105
+
106
+ {
107
+ title : 'Word Wrap' ,
108
+ value : linewrap ,
109
+ options : [
110
+ {
111
+ value : true , label : 'On' , ariaLabel : 'linewrap on' , name : 'linewrap' , id : 'linewrap-on'
112
+ } ,
113
+ {
114
+ value : false , label : 'Off' , ariaLabel : 'linewrap off' , name : 'linewrap' , id : 'linewrap-off'
115
+ } ,
116
+ ] ,
117
+ onSelect : x => setLinewrap ( x )
130
118
}
131
119
] ;
132
120
133
- useEffect ( ( ) => { } ) ;
121
+ // useEffect(() => { });
134
122
135
123
return (
136
124
< Screen >
137
125
< SettingsHeader >
138
- < div >
139
- < h1 > Settings</ h1 >
140
- </ div >
126
+ < h1 > Settings</ h1 >
141
127
142
128
< div style = { { marginLeft : '2rem' } } >
143
-
144
- < IconLinkWrapper to = "/mobile" aria-label = "Return to original editor" >
129
+ < IconLinkWrapper to = "/mobile" aria-label = "Return to ide view" >
145
130
< ExitIcon />
146
131
</ IconLinkWrapper >
147
- </ div >
148
132
133
+ </ div >
149
134
</ SettingsHeader >
150
135
< section className = "preferences" >
151
136
< Content >
152
- { preferences . map ( option => < Selector { ...option } /> ) }
137
+ { preferences . map ( option => < Selector key = { ` ${ option . title } wrapper` } { ...option } /> ) }
153
138
</ Content >
154
139
</ section >
155
140
</ Screen > ) ;
@@ -176,52 +161,10 @@ MobilePreferences.propTypes = {
176
161
setTextOutput : PropTypes . func . isRequired ,
177
162
setGridOutput : PropTypes . func . isRequired ,
178
163
setSoundOutput : PropTypes . func . isRequired ,
179
-
180
-
181
- preferences : PropTypes . shape ( {
182
- fontSize : PropTypes . number . isRequired ,
183
- autosave : PropTypes . bool . isRequired ,
184
- linewrap : PropTypes . bool . isRequired ,
185
- lineNumbers : PropTypes . bool . isRequired ,
186
- lintWarning : PropTypes . bool . isRequired ,
187
- textOutput : PropTypes . bool . isRequired ,
188
- gridOutput : PropTypes . bool . isRequired ,
189
- soundOutput : PropTypes . bool . isRequired ,
190
- theme : PropTypes . string . isRequired ,
191
- autorefreshIdeActions : PropTypes . bool . isRequired
192
- } ) . isRequired ,
193
-
194
- ide : PropTypes . shape ( {
195
- isPlaying : PropTypes . bool . isRequired ,
196
- isAccessibleOutputPlaying : PropTypes . bool . isRequired ,
197
- consoleEvent : PropTypes . array ,
198
- modalIsVisible : PropTypes . bool . isRequired ,
199
- sidebarIsExpanded : PropTypes . bool . isRequired ,
200
- consoleIsExpanded : PropTypes . bool . isRequired ,
201
- preferencesIsVisible : PropTypes . bool . isRequired ,
202
- projectOptionsVisible : PropTypes . bool . isRequired ,
203
- newFolderModalVisible : PropTypes . bool . isRequired ,
204
- shareModalVisible : PropTypes . bool . isRequired ,
205
- shareModalProjectId : PropTypes . string . isRequired ,
206
- shareModalProjectName : PropTypes . string . isRequired ,
207
- shareModalProjectUsername : PropTypes . string . isRequired ,
208
- editorOptionsVisible : PropTypes . bool . isRequired ,
209
- keyboardShortcutVisible : PropTypes . bool . isRequired ,
210
- unsavedChanges : PropTypes . bool . isRequired ,
211
- infiniteLoop : PropTypes . bool . isRequired ,
212
- previewIsRefreshing : PropTypes . bool . isRequired ,
213
- infiniteLoopMessage : PropTypes . string . isRequired ,
214
- projectSavedTime : PropTypes . string ,
215
- previousPath : PropTypes . string . isRequired ,
216
- justOpenedProject : PropTypes . bool . isRequired ,
217
- errorType : PropTypes . string ,
218
- runtimeErrorWarningVisible : PropTypes . bool . isRequired ,
219
- uploadFileModalVisible : PropTypes . bool . isRequired
220
- } ) . isRequired ,
221
164
} ;
222
165
223
166
const mapStateToProps = state => ( {
224
- preferences : state . preferences ,
167
+ ... state . preferences ,
225
168
} ) ;
226
169
227
170
const mapDispatchToProps = dispatch => bindActionCreators ( {
@@ -230,4 +173,4 @@ const mapDispatchToProps = dispatch => bindActionCreators({
230
173
} , dispatch ) ;
231
174
232
175
233
- export default connect ( mapStateToProps , mapDispatchToProps ) ( MobilePreferences ) ;
176
+ export default withRouter ( connect ( mapStateToProps , mapDispatchToProps ) ( MobilePreferences ) ) ;
0 commit comments