diff --git a/packages/@uppy/core/src/Uppy.js b/packages/@uppy/core/src/Uppy.js index fcde7efdfc..d37995c6f5 100644 --- a/packages/@uppy/core/src/Uppy.js +++ b/packages/@uppy/core/src/Uppy.js @@ -21,6 +21,14 @@ import { import packageJson from '../package.json' import locale from './locale.js' + +const getDefaultUploadState = () => ({ + totalProgress: 0, + allowNewUpload: true, + error: null, + recoveredState: null, +}); + /** * Uppy Core module. * Manages plugins, state updates, acts as an event bus, @@ -91,19 +99,17 @@ class Uppy { this.store = this.opts.store this.setState({ + ...getDefaultUploadState(), plugins: {}, files: {}, currentUploads: {}, - allowNewUpload: true, capabilities: { uploadProgress: supportsUploadProgress(), individualCancellation: true, resumableUploads: false, }, - totalProgress: 0, meta: { ...this.opts.meta }, info: [], - recoveredState: null, }) this.#restricter = new Restricter(() => this.opts, this.i18n) @@ -230,6 +236,7 @@ class Uppy { this.setState() // so that UI re-renders with new options } + // todo next major: rename to something better? (it doesn't just reset progress) resetProgress () { const defaultProgress = { percentage: 0, @@ -249,17 +256,16 @@ class Uppy { } }) - this.setState({ - files: updatedFiles, - totalProgress: 0, - allowNewUpload: true, - error: null, - recoveredState: null, - }) + this.setState({ files: updatedFiles, ...getDefaultUploadState() }) this.emit('reset-progress') } + /** @protected */ + clearUploadedFiles () { + this.setState({ ...getDefaultUploadState(), files: {} }) + } + addPreProcessor (fn) { this.#preProcessors.add(fn) } @@ -854,11 +860,8 @@ class Uppy { this.removeFiles(fileIDs, 'cancel-all') } - this.setState({ - totalProgress: 0, - error: null, - recoveredState: null, - }) + this.setState(getDefaultUploadState()) + // todo should we call this.emit('reset-progress') like we do for resetProgress? } } diff --git a/packages/@uppy/core/src/Uppy.test.js b/packages/@uppy/core/src/Uppy.test.js index 78b4c1e717..1e378e6133 100644 --- a/packages/@uppy/core/src/Uppy.test.js +++ b/packages/@uppy/core/src/Uppy.test.js @@ -150,6 +150,7 @@ describe('src/Core', () => { capabilities: { individualCancellation: true, uploadProgress: true, resumableUploads: false }, files: {}, currentUploads: {}, + error: null, allowNewUpload: true, foo: 'baar', info: [], @@ -175,6 +176,7 @@ describe('src/Core', () => { capabilities: { individualCancellation: true, uploadProgress: true, resumableUploads: false }, files: {}, currentUploads: {}, + error: null, allowNewUpload: true, foo: 'bar', info: [], @@ -189,6 +191,7 @@ describe('src/Core', () => { capabilities: { individualCancellation: true, uploadProgress: true, resumableUploads: false }, files: {}, currentUploads: {}, + error: null, allowNewUpload: true, foo: 'baar', info: [], diff --git a/packages/@uppy/dashboard/src/Dashboard.jsx b/packages/@uppy/dashboard/src/Dashboard.jsx index 61cf6e2ff0..2ba20fb934 100644 --- a/packages/@uppy/dashboard/src/Dashboard.jsx +++ b/packages/@uppy/dashboard/src/Dashboard.jsx @@ -67,7 +67,7 @@ export default class Dashboard extends UIPlugin { hidePauseResumeButton: false, hideProgressAfterFinish: false, doneButtonHandler: () => { - this.uppy.cancelAll() + this.uppy.clearUploadedFiles() this.requestCloseModal() }, note: null,