@@ -8,6 +8,7 @@ import {Form, Grid, Segment, Button, Icon, Tab} from 'semantic-ui-react';
88import Dropzone from 'react-dropzone' ;
99
1010import EditorContainer from '../containers/EditorContainer' ;
11+ import { DEFAULT_OUTPUT_FILE_NAME } from '../reducers/code' ;
1112
1213const TAB_CODE = 0 ;
1314const TAB_RESULTS = 2 ;
@@ -20,6 +21,7 @@ class CodeContainer extends Component {
2021 pending : PropTypes . bool ,
2122 hasResults : PropTypes . bool ,
2223 onCodeChange : PropTypes . func ,
24+ onOutputFileNameChange : PropTypes . func ,
2325 onObfuscateClick : PropTypes . func ,
2426 onDownloadCodeClick : PropTypes . func ,
2527 onDownloadSourceMapClick : PropTypes . func ,
@@ -57,8 +59,18 @@ class CodeContainer extends Component {
5759 } ) ;
5860 }
5961
62+ onCodeChange ( code ) {
63+ const { code : prevCode , onCodeChange, onOutputFileNameChange} = this . props ;
64+
65+ onCodeChange ( code ) ;
66+
67+ if ( code !== prevCode ) {
68+ onOutputFileNameChange ( DEFAULT_OUTPUT_FILE_NAME ) ;
69+ }
70+ }
71+
6072 onDrop ( files ) {
61- const { onCodeChange} = this . props ;
73+ const { onCodeChange, onOutputFileNameChange } = this . props ;
6274
6375 if ( ! window . File || ! window . FileReader ) {
6476 alert ( 'Your browser does not support File API' ) ;
@@ -69,6 +81,7 @@ class CodeContainer extends Component {
6981
7082 reader . onload = ( event ) => {
7183 onCodeChange ( event . target . result ) ;
84+ onOutputFileNameChange ( file . name ) ;
7285 this . onTabClick ( TAB_CODE ) ;
7386 } ;
7487
@@ -146,7 +159,6 @@ class CodeContainer extends Component {
146159 code,
147160 obfuscatedCode,
148161 pending,
149- onCodeChange,
150162 onObfuscateClick,
151163 onDownloadCodeClick,
152164 onDownloadSourceMapClick,
@@ -159,7 +171,7 @@ class CodeContainer extends Component {
159171 menuItem : 'Copy & Paste JavaScript Code' ,
160172 render : ( ) => (
161173 < Pane >
162- < EditorContainer onBlur = { onCodeChange } value = { code } />
174+ < EditorContainer onBlur = { :: this . onCodeChange } value = { code } />
163175 < Segment basic >
164176 < Button
165177 loading = { pending }
@@ -177,7 +189,11 @@ class CodeContainer extends Component {
177189 menuItem : 'Upload JavaScript File' ,
178190 render : ( ) => (
179191 < Pane >
180- < Dropzone onDrop = { ::this . onDrop } multiple = { false } className = "DropZone" >
192+ < Dropzone
193+ onDrop = { ::this . onDrop }
194+ multiple = { false }
195+ className = "DropZone"
196+ >
181197 < div > Try dropping some file here, or click to select file to upload.</ div >
182198 </ Dropzone >
183199 </ Pane >
0 commit comments