From 7fac8d8edd5dc0ff8565cbb65676a3b81f2471b0 Mon Sep 17 00:00:00 2001 From: Minh Duc Vo Date: Mon, 22 Apr 2019 22:03:41 +0700 Subject: [PATCH] CodeBox : Re-enable uploader if no file chosen If no file is chosen and the previous state is identical, the upload button will still be locked and unclickable. --- src/app/problemList/codeEditor/codeBox.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/app/problemList/codeEditor/codeBox.js b/src/app/problemList/codeEditor/codeBox.js index f4f219a..d7711b7 100644 --- a/src/app/problemList/codeEditor/codeBox.js +++ b/src/app/problemList/codeEditor/codeBox.js @@ -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' } @@ -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(); + }} /> );