If one post fails to upload, don't prevent the rest from uploading

This commit is contained in:
Ruin0x11 2021-05-07 23:02:59 -07:00
parent ca77149597
commit f4ca435657
1 changed files with 32 additions and 25 deletions

View File

@ -12,7 +12,7 @@ const PostUploadView = require("../views/post_upload_view.js");
const EmptyView = require("../views/empty_view.js"); const EmptyView = require("../views/empty_view.js");
const genericErrorMessage = const genericErrorMessage =
"One of the posts needs your attention; " + "One or more posts needs your attention; " +
'click "resume upload" when you\'re ready.'; 'click "resume upload" when you\'re ready.';
class PostUploadController { class PostUploadController {
@ -55,6 +55,7 @@ class PostUploadController {
_evtSubmit(e) { _evtSubmit(e) {
this._view.disableForm(); this._view.disableForm();
this._view.clearMessages(); this._view.clearMessages();
let anyFailures = false;
e.detail.uploadables e.detail.uploadables
.reduce( .reduce(
@ -64,37 +65,43 @@ class PostUploadController {
uploadable, uploadable,
e.detail.skipDuplicates e.detail.skipDuplicates
) )
), .catch((error) => {
Promise.resolve() anyFailures = true;
)
.then(
() => {
this._view.clearMessages();
misc.disableExitConfirmation();
const ctx = router.show(uri.formatClientLink("posts"));
ctx.controller.showSuccess("Posts uploaded.");
},
(error) => {
if (error.uploadable) { if (error.uploadable) {
if (error.similarPosts) { if (error.similarPosts) {
error.uploadable.lookalikes = error.similarPosts; error.uploadable.lookalikes = error.similarPosts;
this._view.updateUploadable(error.uploadable); this._view.updateUploadable(error.uploadable);
this._view.showInfo(genericErrorMessage);
this._view.showInfo( this._view.showInfo(
error.message, error.message,
error.uploadable error.uploadable
); );
} else { } else {
this._view.showError(genericErrorMessage);
this._view.showError( this._view.showError(
error.message, error.message,
error.uploadable error.uploadable
); );
} }
} else { } else {
this._view.showError(error.message); this._view.showError(
error.message,
error.uploadable
);
} }
})
),
Promise.resolve()
)
.then(
() => {
if (anyFailures) {
this._view.showError(genericErrorMessage);
this._view.enableForm(); this._view.enableForm();
} else {
this._view.clearMessages();
misc.disableExitConfirmation();
const ctx = router.show(uri.formatClientLink("posts"));
ctx.controller.showSuccess("Posts uploaded.");
}
} }
); );
} }