diff --git a/plugins/uploader-resources/src/components/FileUploadStatusBar.svelte b/plugins/uploader-resources/src/components/FileUploadStatusBar.svelte index 9e0f45a3db..a7070e0df7 100644 --- a/plugins/uploader-resources/src/components/FileUploadStatusBar.svelte +++ b/plugins/uploader-resources/src/components/FileUploadStatusBar.svelte @@ -28,44 +28,30 @@ let state: UppyState = 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 { diff --git a/plugins/uploader-resources/src/components/FileUploadStatusPopup.svelte b/plugins/uploader-resources/src/components/FileUploadStatusPopup.svelte index 1a23c485cb..717a8c3508 100644 --- a/plugins/uploader-resources/src/components/FileUploadStatusPopup.svelte +++ b/plugins/uploader-resources/src/components/FileUploadStatusPopup.svelte @@ -40,28 +40,21 @@ let state: UppyState = 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() @@ -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): string | undefined {