summaryrefslogtreecommitdiff
path: root/client/js/controllers
diff options
context:
space:
mode:
authorShyam Sunder <sgsunder1@gmail.com>2021-09-13 13:28:34 -0400
committerShyam Sunder <sgsunder1@gmail.com>2021-09-13 13:28:34 -0400
commitbe0c867d25897da50b6df1b969b7e21bca2fa888 (patch)
tree66de9792906b83c8fedf4bfdcc984aac5c24dbbc /client/js/controllers
parente4a253fd2579719add519efa83c2aa28e3cb9a92 (diff)
parentf5338ca508bdcc0a2b30fe98dd3734f6343d407e (diff)
client/upload: add QoL features for bulk uploads
* Continue uploading remaining posts in an upload list even when one fails * Allow option to continue uploading even when similar posts are found Closes #400
Diffstat (limited to 'client/js/controllers')
-rw-r--r--client/js/controllers/post_upload_controller.js71
1 files changed, 41 insertions, 30 deletions
diff --git a/client/js/controllers/post_upload_controller.js b/client/js/controllers/post_upload_controller.js
index d317be5..a54baec 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(
@@ -62,44 +63,51 @@ class PostUploadController {
promise.then(() =>
this._uploadSinglePost(
uploadable,
- e.detail.skipDuplicates
- )
+ e.detail.skipDuplicates,
+ e.detail.alwaysUploadSimilar
+ ).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,
+ uploadable
+ );
+ }
+ })
),
Promise.resolve()
)
- .then(
- () => {
+ .then(() => {
+ if (anyFailures) {
+ this._view.showError(genericErrorMessage);
+ this._view.enableForm();
+ } else {
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
- );
- }
- } else {
- this._view.showError(error.message);
- }
- this._view.enableForm();
}
- );
+ });
}
- _uploadSinglePost(uploadable, skipDuplicates) {
+ _uploadSinglePost(uploadable, skipDuplicates, alwaysUploadSimilar) {
progress.start();
let reverseSearchPromise = Promise.resolve();
if (!uploadable.lookalikesConfirmed) {
@@ -128,7 +136,10 @@ class PostUploadController {
}
// notify about similar posts
- if (searchResult.similarPosts.length) {
+ if (
+ searchResult.similarPosts.length &&
+ !alwaysUploadSimilar
+ ) {
let error = new Error(
`Found ${searchResult.similarPosts.length} similar ` +
"posts.\nYou can resume or discard this upload."