fix: bad state removing last file from a paused queue

Massimo Melina committed Jan 21, 2023 at 15:44 UTC f0c877b8049e50c8590e4fe8e2bef94db80e62d9
1 file changed +7 -5
frontend/src/upload.ts
+7 -5
@@ -82,8 +82,8 @@ export function showUpload() {
82 `(${_.sumBy(qs, q => q.files.length)})`,
83 h('button',{
84 onClick(){
85 - abortCurrentUpload()
85 uploadState.qs = []
86 + abortCurrentUpload()
87 }
88 }, "Clear"),
89 h('button',{
@@ -99,9 +99,11 @@ export function showUpload() {
99 files: Array.from(q.files),
100 remove(f) {
101 if (f === uploadState.uploading)
102 - abortCurrentUpload()
103 - else
104 - _.pull(uploadState.qs[idx].files, f)
102 + return abortCurrentUpload()
103 + const q = uploadState.qs[idx]
104 + _.pull(q.files, f)
105 + if (!q.files.length)
106 + uploadState.qs.splice(idx,1)
107 }
108 }),
109 ))
@@ -145,7 +147,7 @@ function iconBtn(icon: string, onClick: () => any, { small=true, style={}, ...pr
147 return h('button', { onClick, ...props, ...small && { style: { padding: '.1em', ...style } } }, hIcon(icon))
148 }
149
148 -/// Manage uploadQ
150 +/// Manage upload queue
151
152 let controller: AbortController | undefined
153 subscribe(uploadState, () => {