From e7cf9a44a0ac4f27c5ba64690ef616dd3d49b9eb Mon Sep 17 00:00:00 2001 From: Brett Sun Date: Wed, 9 Dec 2015 15:57:01 +0100 Subject: [PATCH] Add simple check for determining if user's offline while uploading --- js/components/ascribe_uploader/react_s3_fine_uploader.js | 8 ++++++-- js/constants/error_constants.js | 3 +++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/js/components/ascribe_uploader/react_s3_fine_uploader.js b/js/components/ascribe_uploader/react_s3_fine_uploader.js index b11a877f..19705925 100644 --- a/js/components/ascribe_uploader/react_s3_fine_uploader.js +++ b/js/components/ascribe_uploader/react_s3_fine_uploader.js @@ -479,8 +479,12 @@ const ReactS3FineUploader = React.createClass({ } else { matchedErrorClass = testErrorAgainstAll({ type, reason, xhr }); - // If none found, show the next error message - if (!matchedErrorClass) { + // If none found, check the internet connection + // TODO: use a better mechanism for checking network state, ie. offline.js + if ('onLine' in window.navigator && !window.navigator.onLine) { + matchedErrorClass = ErrorClasses.upload.offline; + } else { + // Otherwise, show the next error message in the queue matchedErrorClass = ErrorQueueStore.getNextError('upload'); } } diff --git a/js/constants/error_constants.js b/js/constants/error_constants.js index 19e06c18..d649e551 100644 --- a/js/constants/error_constants.js +++ b/js/constants/error_constants.js @@ -121,6 +121,9 @@ const ErrorClasses = { }, 'contactUs': { 'prettifiedText': getLangText("We're having a really hard time with your upload. Please contact us for more help.") + }, + 'offline': { + 'prettifiedText': getLangText('It looks like your Internet connection might have gone down during the upload. Please check your connection and try again.') } }, 'default': {