Skip to content

Commit

Permalink
fix: properly update uppy state (#6252)
Browse files Browse the repository at this point in the history
Signed-off-by: Alexander Onnikov <Alexander.Onnikov@xored.com>
  • Loading branch information
aonnikov authored Aug 5, 2024
1 parent 7bf2a7c commit f95f2b1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,44 +28,30 @@
let state: UppyState<any, any> = upload.uppy.getState()
let progress: number = state.totalProgress
$: state = upload.uppy.getState()
$: progress = state.totalProgress
$: files = Object.values(state.files)
$: filesTotal = files.length
$: filesComplete = files.filter((p) => p.progress?.uploadComplete).length
function handleProgress (totalProgress: number): void {
progress = totalProgress
}
function handleUploadProgress (): void {
state = upload.uppy.getState()
}
function handleUploadSuccess (): void {
state = upload.uppy.getState()
}
function handleFileRemoved (): void {
state = upload.uppy.getState()
}
function handleError (): void {
function updateState (): void {
state = upload.uppy.getState()
}
onMount(() => {
upload.uppy.on('error', handleError)
upload.uppy.on('progress', handleProgress)
upload.uppy.on('upload-progress', handleUploadProgress)
upload.uppy.on('upload-success', handleUploadSuccess)
upload.uppy.on('file-removed', handleFileRemoved)
upload.uppy.on('error', updateState)
upload.uppy.on('progress', updateState)
upload.uppy.on('upload-progress', updateState)
upload.uppy.on('upload-success', updateState)
upload.uppy.on('file-removed', updateState)
})
onDestroy(() => {
upload.uppy.off('error', handleError)
upload.uppy.off('progress', handleProgress)
upload.uppy.off('upload-progress', handleUploadProgress)
upload.uppy.off('upload-success', handleUploadSuccess)
upload.uppy.off('file-removed', handleFileRemoved)
upload.uppy.off('error', updateState)
upload.uppy.off('progress', updateState)
upload.uppy.off('upload-progress', updateState)
upload.uppy.off('upload-success', updateState)
upload.uppy.off('file-removed', updateState)
})
function handleClick (ev: MouseEvent): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,28 +40,21 @@
let state: UppyState<any, any> = upload.uppy.getState()
$: state = upload.uppy.getState()
$: files = Object.values(state.files)
$: capabilities = state.capabilities ?? {}
$: individualCancellation = 'individualCancellation' in capabilities && capabilities.individualCancellation
function updateState (): void {
state = upload.uppy.getState()
}
function handleComplete (): void {
if (upload.uppy.getState().error === undefined) {
dispatch('close')
}
}
function handleUploadError (): void {
state = upload.uppy.getState()
}
function handleUploadProgress (): void {
state = upload.uppy.getState()
}
function handleUploadSuccess (): void {
state = upload.uppy.getState()
}
function handleFileRemoved (): void {
state = upload.uppy.getState()
const files = upload.uppy.getFiles()
Expand All @@ -84,18 +77,18 @@
onMount(() => {
upload.uppy.on('complete', handleComplete)
upload.uppy.on('upload-error', handleUploadError)
upload.uppy.on('upload-progress', handleUploadProgress)
upload.uppy.on('upload-success', handleUploadSuccess)
upload.uppy.on('file-removed', handleFileRemoved)
upload.uppy.on('upload-error', updateState)
upload.uppy.on('upload-progress', updateState)
upload.uppy.on('upload-success', updateState)
})
onDestroy(() => {
upload.uppy.off('complete', handleComplete)
upload.uppy.off('upload-error', handleUploadError)
upload.uppy.off('upload-progress', handleUploadProgress)
upload.uppy.off('upload-success', handleUploadSuccess)
upload.uppy.off('file-removed', handleFileRemoved)
upload.uppy.off('upload-error', updateState)
upload.uppy.off('upload-progress', updateState)
upload.uppy.off('upload-success', updateState)
})
function getFileError (file: UppyFile<any, any>): string | undefined {
Expand Down

0 comments on commit f95f2b1

Please sign in to comment.