@@ -3,9 +3,8 @@ import PropTypes from 'prop-types';
3
3
4
4
import { connect } from 'react-redux' ;
5
5
6
- import { Form , Grid , Segment , Button , Icon } from 'semantic-ui-react' ;
6
+ import { Form , Grid , Segment , Button , Icon , Tab } from 'semantic-ui-react' ;
7
7
8
- import classNames from 'classnames' ;
9
8
import Dropzone from 'react-dropzone' ;
10
9
11
10
import EditorContainer from '../containers/EditorContainer' ;
@@ -60,15 +59,21 @@ class CodeContainer extends Component {
60
59
}
61
60
62
61
onDrop ( files ) {
62
+ const { onCodeChange} = this . props ;
63
+
64
+ if ( ! window . File || ! window . FileReader ) {
65
+ alert ( 'Your browser does not support File API' ) ;
66
+ }
67
+
63
68
const file = files [ 0 ] ;
64
69
const reader = new FileReader ( ) ;
65
70
66
71
reader . onload = ( event ) => {
67
- this . props . onCodeChange ( event . target . result ) ;
72
+ onCodeChange ( event . target . result ) ;
73
+ this . onTabClick ( TAB_CODE ) ;
68
74
} ;
69
75
70
76
reader . readAsText ( file ) ;
71
-
72
77
}
73
78
74
79
toggleEvaluate = ( ) => {
@@ -135,12 +140,9 @@ class CodeContainer extends Component {
135
140
136
141
done = true ;
137
142
flush ( ) ;
138
-
139
143
}
140
144
141
- render ( ) {
142
- const tabIndex = this . state . selectedTabIndex ;
143
-
145
+ buildPanes ( ) {
144
146
const {
145
147
code,
146
148
obfuscatedCode,
@@ -153,87 +155,102 @@ class CodeContainer extends Component {
153
155
hasObfuscatedCode,
154
156
} = this . props ;
155
157
156
- return (
157
- < div >
158
-
159
- < div className = "ui top attached stackable three item menu" >
160
- < Title active = { tabIndex === TAB_CODE } onClick = { ( ) => this . onTabClick ( TAB_CODE ) } > Copy & Paste
161
- JavaScript Code </ Title >
162
- < Title active = { tabIndex === TAB_UPLOAD } onClick = { ( ) => this . onTabClick ( TAB_UPLOAD ) } > Upload
163
- JavaScript Files</ Title >
164
- < Title active = { tabIndex === TAB_RESULTS } onClick = { ( ) => this . onTabClick ( TAB_RESULTS ) } > Output</ Title >
165
- </ div >
166
-
167
- < Pane active = { tabIndex === TAB_CODE } >
168
- < EditorContainer onBlur = { onCodeChange } value = { code } />
169
- < Segment basic >
170
- < Button
171
- loading = { pending }
172
- disabled = { pending }
173
- primary
174
- onClick = { onObfuscateClick }
175
- >
176
- Obfuscate
177
- </ Button >
178
- </ Segment >
179
- </ Pane >
180
-
181
- < Pane active = { tabIndex === TAB_UPLOAD } >
182
- < Dropzone onDrop = { ::this . onDrop } multiple = { false } className = "DropZone" >
183
- < div > Try dropping some files here, or click to select files to upload.</ div >
184
- </ Dropzone >
185
- </ Pane >
186
-
187
- < Pane active = { tabIndex === TAB_RESULTS } >
188
- < Form >
189
- < Form . TextArea
190
- value = { obfuscatedCode }
191
- onFocus = { ( event ) => event . target . select ( ) }
192
- />
193
- </ Form >
194
-
195
- < Grid columns = { 2 } relaxed >
196
- < Grid . Column width = { 13 } >
158
+ return [
159
+ {
160
+ menuItem : 'Copy & Paste JavaScript Code' ,
161
+ render : ( ) => (
162
+ < Pane >
163
+ < EditorContainer onBlur = { onCodeChange } value = { code } />
164
+ < Segment basic >
165
+ < Button
166
+ loading = { pending }
167
+ disabled = { pending }
168
+ primary
169
+ onClick = { onObfuscateClick }
170
+ >
171
+ Obfuscate
172
+ </ Button >
173
+ </ Segment >
174
+ </ Pane >
175
+ )
176
+ } ,
177
+ {
178
+ menuItem : 'Upload JavaScript File' ,
179
+ render : ( ) => (
180
+ < Pane >
181
+ < Dropzone onDrop = { ::this . onDrop } multiple = { false } className = "DropZone" >
182
+ < div > Try dropping some file here, or click to select file to upload.</ div >
183
+ </ Dropzone >
184
+ </ Pane >
185
+ )
186
+ } ,
187
+ {
188
+ menuItem : 'Output' ,
189
+ render : ( ) => (
190
+ < Pane >
191
+ < Form >
192
+ < Form . TextArea
193
+ value = { obfuscatedCode }
194
+ onFocus = { ( event ) => event . target . select ( ) }
195
+ />
196
+ </ Form >
197
+
198
+ < Grid stackable columns = { 2 } relaxed >
199
+ < Grid . Column width = { 13 } >
200
+ < Segment basic >
201
+ < Button
202
+ disabled = { ! hasObfuscatedCode }
203
+ onClick = { onDownloadCodeClick }
204
+ >
205
+ < Icon name = 'download' /> Download obfuscated code
206
+ </ Button >
207
+ { hasSourceMap &&
208
+ < Button
209
+ onClick = { onDownloadSourceMapClick }
210
+ >
211
+ < Icon name = 'download' /> Download source map file
212
+ </ Button >
213
+ }
214
+ </ Segment >
215
+ </ Grid . Column >
216
+
217
+ < Grid . Column width = { 3 } >
218
+ < Segment basic >
219
+ < Form . Checkbox
220
+ label = 'Evaluate'
221
+ checked = { this . state . evaluate }
222
+ onChange = { this . toggleEvaluate } />
223
+ </ Segment >
224
+ </ Grid . Column >
225
+ </ Grid >
226
+
227
+ { this . state . evaluate &&
197
228
< Segment basic >
198
- < Button
199
- disabled = { ! hasObfuscatedCode }
200
- onClick = { onDownloadCodeClick }
201
- >
202
- < Icon name = 'download' /> Download obfuscated code
203
- </ Button >
204
- { hasSourceMap &&
205
- < Button
206
- onClick = { onDownloadSourceMapClick }
207
- >
208
- < Icon name = 'download' /> Download source map file
209
- </ Button >
210
- }
229
+ < div className = "evaluatedCode" >
230
+ { this . state . evaluatedResult }
231
+ </ div >
211
232
</ Segment >
212
- </ Grid . Column >
233
+ }
234
+ </ Pane >
235
+ )
236
+ }
237
+ ] ;
238
+ }
213
239
214
- < Grid . Column width = { 3 } >
215
- < Segment basic >
216
- < Form . Checkbox
217
- label = 'Evaluate'
218
- checked = { this . state . evaluate }
219
- onChange = { this . toggleEvaluate } />
220
- </ Segment >
221
- </ Grid . Column >
222
- </ Grid >
223
-
224
- { this . state . evaluate &&
225
- < Segment basic >
226
- < div className = "evaluatedCode" >
227
- { this . state . evaluatedResult }
228
- </ div >
229
- </ Segment >
230
- }
231
- </ Pane >
240
+ render ( ) {
241
+ const tabIndex = this . state . selectedTabIndex ;
232
242
243
+ return (
244
+ < div >
245
+ < Tab
246
+ activeIndex = { tabIndex }
247
+ menu = { { attached : 'top' , stackable : true , widths : 'three' } }
248
+ panes = { this . buildPanes ( ) }
249
+ onTabChange = { ( event , data ) => this . onTabClick ( data . activeIndex ) }
250
+ />
233
251
</ div >
234
252
) ;
235
253
}
236
-
237
254
}
238
255
239
256
const mapStateToProps = ( state ) => {
@@ -248,32 +265,13 @@ export default connect(mapStateToProps)(CodeContainer);
248
265
249
266
250
267
const Pane = ( props ) => {
251
- const className = classNames ( 'ui bottom attached tab segment' . split ( ' ' ) , { 'active' : props . active } ) ;
252
268
return (
253
- < div className = { className } >
269
+ < div className = "ui bottom attached tab segment active" >
254
270
{ props . children }
255
271
</ div >
256
272
)
257
273
} ;
258
274
259
275
Pane . propTypes = {
260
- active : PropTypes . bool . isRequired ,
261
- children : PropTypes . node . isRequired ,
262
- } ;
263
-
264
-
265
- const Title = ( props ) => {
266
- const className = classNames ( 'item' , { 'active' : props . active } ) ;
267
-
268
- return (
269
- < a className = { className } onClick = { props . onClick } >
270
- { props . children }
271
- </ a >
272
- )
273
- } ;
274
-
275
- Title . propTypes = {
276
- active : PropTypes . bool . isRequired ,
277
276
children : PropTypes . node . isRequired ,
278
- onClick : PropTypes . func . isRequired ,
279
277
} ;
0 commit comments