Skip to content

Commit

Permalink
don't cancel all files when clicking "done" (#4771)
Browse files Browse the repository at this point in the history
* don't cancel assembly when clicking "done"

* Reset state to default when Done button is pressed

* reuse code

* Apply suggestions from code review

Co-authored-by: Artur Paikin <artur@arturpaikin.com>

---------

Co-authored-by: Artur Paikin <artur@arturpaikin.com>
  • Loading branch information
mifi and arturi authored Nov 7, 2023
1 parent 51ecc66 commit d72a937
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 16 deletions.
33 changes: 18 additions & 15 deletions packages/@uppy/core/src/Uppy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand All @@ -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)
}
Expand Down Expand Up @@ -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?
}
}

Expand Down
3 changes: 3 additions & 0 deletions packages/@uppy/core/src/Uppy.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ describe('src/Core', () => {
capabilities: { individualCancellation: true, uploadProgress: true, resumableUploads: false },
files: {},
currentUploads: {},
error: null,
allowNewUpload: true,
foo: 'baar',
info: [],
Expand All @@ -175,6 +176,7 @@ describe('src/Core', () => {
capabilities: { individualCancellation: true, uploadProgress: true, resumableUploads: false },
files: {},
currentUploads: {},
error: null,
allowNewUpload: true,
foo: 'bar',
info: [],
Expand All @@ -189,6 +191,7 @@ describe('src/Core', () => {
capabilities: { individualCancellation: true, uploadProgress: true, resumableUploads: false },
files: {},
currentUploads: {},
error: null,
allowNewUpload: true,
foo: 'baar',
info: [],
Expand Down
2 changes: 1 addition & 1 deletion packages/@uppy/dashboard/src/Dashboard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit d72a937

Please sign in to comment.