mirror of
https://github.com/ascribe/onion.git
synced 2024-12-22 09:23:13 +01:00
Add error queue store
Allows errors to be queued for showing to the user, such as in the uploader’s error states.
This commit is contained in:
parent
dff180ff87
commit
01e3fd5fcd
13
js/actions/error_queue_actions.js
Normal file
13
js/actions/error_queue_actions.js
Normal file
@ -0,0 +1,13 @@
|
||||
'use strict';
|
||||
|
||||
import { alt } from '../alt';
|
||||
|
||||
class ErrorQueueActions {
|
||||
constructor() {
|
||||
this.generateActions(
|
||||
'shiftErrorQueue'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default alt.createActions(ErrorQueueActions);
|
@ -111,6 +111,17 @@ const ErrorClasses = {
|
||||
'are working to resolve them. Please try again in a few hours.'),
|
||||
'test': 'Problem signing the chunk'
|
||||
},
|
||||
|
||||
// Fallback error tips
|
||||
'slowConnection': {
|
||||
'prettifiedText': getLangText('Are you on a slow or unstable network? Uploading large files requires a fast Internet connection.')
|
||||
},
|
||||
'tryDifferentBrowser': {
|
||||
'prettifiedText': getLangText("We still can't seem to upload your file. Maybe try another browser?")
|
||||
},
|
||||
'contactUs': {
|
||||
'prettifiedText': getLangText("We're having a really hard time with your upload. Please contact us for more help.")
|
||||
}
|
||||
},
|
||||
'default': {
|
||||
'default': {
|
||||
@ -120,10 +131,12 @@ const ErrorClasses = {
|
||||
};
|
||||
|
||||
// Dynamically inject the name and group properties into the classes
|
||||
Object.keys(ErrorClasses).forEach((errorGroup) => {
|
||||
Object.keys(ErrorClasses[errorGroup]).forEach((errorClass) => {
|
||||
errorClass.name = errorClass;
|
||||
errorClass.group = errorGroup;
|
||||
Object.keys(ErrorClasses).forEach((errorGroupKey) => {
|
||||
const errorGroup = ErrorClasses[errorGroupKey];
|
||||
Object.keys(errorGroup).forEach((errorClassKey) => {
|
||||
const errorClass = errorGroup[errorClassKey];
|
||||
errorClass.name = errorClassKey;
|
||||
errorClass.group = errorGroupKey;
|
||||
});
|
||||
});
|
||||
|
||||
|
52
js/stores/error_queue_store.js
Normal file
52
js/stores/error_queue_store.js
Normal file
@ -0,0 +1,52 @@
|
||||
'use strict';
|
||||
|
||||
import { alt } from '../alt';
|
||||
|
||||
import ErrorQueueActions from '../actions/error_queue_actions.js';
|
||||
|
||||
import { ErrorClasses } from '../constants/error_constants.js';
|
||||
|
||||
class ErrorQueueStore {
|
||||
constructor() {
|
||||
const { upload: { slowConnection, tryDifferentBrowser } } = ErrorClasses;
|
||||
|
||||
this.errorQueue = {
|
||||
'upload': {
|
||||
queue: [slowConnection, tryDifferentBrowser],
|
||||
loop: true
|
||||
}
|
||||
};
|
||||
|
||||
// Add intial index to each error queue
|
||||
Object
|
||||
.keys(this.errorQueue)
|
||||
.forEach((type) => {
|
||||
this.errorQueue[type].index = 0;
|
||||
});
|
||||
|
||||
this.exportPublicMethods({
|
||||
getNextError: this.getNextError
|
||||
});
|
||||
}
|
||||
|
||||
getNextError(type) {
|
||||
const errorQueue = this.errorQueues[type];
|
||||
const { queue, index } = errorQueue;
|
||||
|
||||
ErrorQueueActions.shiftErrorQueue(type);
|
||||
return queue[index];
|
||||
}
|
||||
|
||||
onShiftQueue(type) {
|
||||
const errorQueue = this.errorQueues[type];
|
||||
const { queue, loop } = errorQueue;
|
||||
|
||||
++errorQueue.index;
|
||||
if (loop) {
|
||||
// Loop back to the beginning if all errors have been exhausted
|
||||
errorQueue.index %= queue.length;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default alt.createStore(ErrorQueueStore, 'ErrorQueueStore');
|
Loading…
Reference in New Issue
Block a user