From f4ca435657ae3882ce28fb3f427f9e0874733282 Mon Sep 17 00:00:00 2001 From: Ruin0x11 Date: Fri, 7 May 2021 23:02:59 -0700 Subject: [PATCH] If one post fails to upload, don't prevent the rest from uploading --- .../js/controllers/post_upload_controller.js | 57 +++++++++++-------- 1 file changed, 32 insertions(+), 25 deletions(-) diff --git a/client/js/controllers/post_upload_controller.js b/client/js/controllers/post_upload_controller.js index d317be59..cfebb0a1 100644 --- a/client/js/controllers/post_upload_controller.js +++ b/client/js/controllers/post_upload_controller.js @@ -12,7 +12,7 @@ const PostUploadView = require("../views/post_upload_view.js"); const EmptyView = require("../views/empty_view.js"); const genericErrorMessage = - "One of the posts needs your attention; " + + "One or more posts needs your attention; " + 'click "resume upload" when you\'re ready.'; class PostUploadController { @@ -55,6 +55,7 @@ class PostUploadController { _evtSubmit(e) { this._view.disableForm(); this._view.clearMessages(); + let anyFailures = false; e.detail.uploadables .reduce( @@ -64,37 +65,43 @@ class PostUploadController { uploadable, e.detail.skipDuplicates ) + .catch((error) => { + anyFailures = true; + if (error.uploadable) { + if (error.similarPosts) { + error.uploadable.lookalikes = error.similarPosts; + this._view.updateUploadable(error.uploadable); + this._view.showInfo( + error.message, + error.uploadable + ); + } else { + this._view.showError( + error.message, + error.uploadable + ); + } + } else { + this._view.showError( + error.message, + error.uploadable + ); + } + }) ), Promise.resolve() ) .then( () => { - this._view.clearMessages(); - misc.disableExitConfirmation(); - const ctx = router.show(uri.formatClientLink("posts")); - ctx.controller.showSuccess("Posts uploaded."); - }, - (error) => { - if (error.uploadable) { - if (error.similarPosts) { - error.uploadable.lookalikes = error.similarPosts; - this._view.updateUploadable(error.uploadable); - this._view.showInfo(genericErrorMessage); - this._view.showInfo( - error.message, - error.uploadable - ); - } else { - this._view.showError(genericErrorMessage); - this._view.showError( - error.message, - error.uploadable - ); - } + if (anyFailures) { + this._view.showError(genericErrorMessage); + this._view.enableForm(); } else { - this._view.showError(error.message); + this._view.clearMessages(); + misc.disableExitConfirmation(); + const ctx = router.show(uri.formatClientLink("posts")); + ctx.controller.showSuccess("Posts uploaded."); } - this._view.enableForm(); } ); }