From 51bcc323af3f259f84e5ea146ff11f8451e0a02f Mon Sep 17 00:00:00 2001 From: Roland Date: Tue, 21 Dec 2021 09:54:38 -0700 Subject: [PATCH] Disabling download button when form is pending. --- app/src/components/Upload.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/app/src/components/Upload.js b/app/src/components/Upload.js index de4356cd..1338ba61 100644 --- a/app/src/components/Upload.js +++ b/app/src/components/Upload.js @@ -10,14 +10,20 @@ class Downloader extends React.Component { this.state = { urls: '', valid: true, + pending: false, }; } submitDownload = async () => { if (this.state.urls) { - let response = await postDownload(this.state.urls); - if (response.status === 204) { - this.setState({urls: ''}); + this.setState({pending: true}); + try { + let response = await postDownload(this.state.urls); + if (response.status === 204) { + this.setState({urls: '', pending: false}); + } + } finally { + this.setState({pending: false}); } } } @@ -42,7 +48,7 @@ class Downloader extends React.Component { render() { let textareaPlaceholder = 'Enter one URL per line'; - let disabled = !this.state.urls || !this.state.valid; + let disabled = !this.state.urls || !this.state.valid || this.state.pending; return (