client/posts: wrap with big progress

fixes #114
This commit is contained in:
rr- 2017-01-08 22:24:46 +01:00
parent e5f08b454c
commit 43198daba3
3 changed files with 35 additions and 5 deletions

View file

@ -1,10 +1,10 @@
'use strict';
const nprogress = require('nprogress');
const cookies = require('js-cookie');
const request = require('superagent');
const config = require('./config.js');
const events = require('./events.js');
const progress = require('./util/progress.js');
class Api extends events.EventTarget {
constructor() {
@ -259,18 +259,18 @@ class Api extends events.EventTarget {
}
if (!options.noProgress) {
nprogress.start();
progress.start();
}
abortFunction = () => {
req.abort(); // does *NOT* call the callback passed in .end()
nprogress.done();
progress.done();
reject(
new Error('The request was aborted due to user cancel.'));
};
req.end((error, response) => {
nprogress.done();
progress.done();
abortFunction = () => {};
if (error) {
if (response && response.body) {

View file

@ -3,6 +3,7 @@
const api = require('../api.js');
const router = require('../router.js');
const misc = require('../util/misc.js');
const progress = require('../util/progress.js');
const topNavigation = require('../models/top_navigation.js');
const Post = require('../models/post.js');
const PostUploadView = require('../views/post_upload_view.js');
@ -83,6 +84,7 @@ class PostUploadController {
}
_uploadSinglePost(uploadable, skipDuplicates) {
progress.start();
let reverseSearchPromise = Promise.resolve();
if (!uploadable.lookalikesConfirmed) {
reverseSearchPromise =
@ -121,8 +123,12 @@ class PostUploadController {
});
this._lastCancellablePromise = savePromise;
return savePromise;
}).catch(error => {
}).then(result => {
progress.done();
return Promise.resolve(result);
}, error => {
error.uploadable = uploadable;
progress.done();
return Promise.reject(error);
});
}

View file

@ -0,0 +1,24 @@
const nprogress = require('nprogress');
let nesting = 0;
function start() {
if (!nesting) {
nprogress.start();
}
nesting++;
}
function done() {
nesting--;
if (nesting > 0) {
nprogress.inc();
} else {
nprogress.done();
}
}
module.exports = {
start: start,
done: done,
};