Skip to content

Commit

Permalink
CodeBox : Re-enable uploader if no file chosen
Browse files Browse the repository at this point in the history
If no file is chosen and the previous state is identical,
the upload button will still be locked and unclickable.
  • Loading branch information
minhducsun2002 committed Apr 22, 2019
1 parent 18f8c81 commit 7fac8d8
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/app/problemList/codeEditor/codeBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,15 @@ class CodeBox extends React.PureComponent {
this.catcherRef.current.click();
}

enable = () => this.setState({ fileLoading: false });

processFile(file) {
let enable = () => this.setState({ fileLoading: false });
if (!(file instanceof Blob) && !(file instanceof File))
// non-File input, hmm..
return enable();
return this.enable();
if (file.size >= byte_limit) {
// 15 KiB limit
enable();
this.enable();
return this.props.enqueueSnackbar(
translations[this.props.globalState.language].resources.problems.codeEditor.error.tooLarge,
{ variant: 'error' }
Expand Down Expand Up @@ -179,7 +180,10 @@ class CodeBox extends React.PureComponent {
onChange={event => this.processFile(event.target.files[0])}
ref={this.catcherRef}
style={{ display: 'none' }}
onClick={event => (event.target.value = null)}
onClick={event => {
event.target.value = null;
if (event.target.files.length < 1) this.enable();
}}
/>
</>
);
Expand Down

0 comments on commit 7fac8d8

Please sign in to comment.