@samitouri / QOSami-HFS / commits / a441b598

upload: cancel resume dialog as soon as we pass the size of the partial file on server

Massimo Melina committed Jun 7, 2023 at 14:13 UTC a441b5981f72c1fb69395a8d52c1278ce1ce6e2e
1 file changed +6 -1
frontend/src/upload.ts
+6 -1
@@ -21,6 +21,7 @@ import { apiCall, getNotification } from '@hfs/shared/api'
21 import { state, useSnapState } from './state'
22 import { Link } from 'react-router-dom'
23 import { t } from './i18n'
24 +import { subscribeKey } from 'valtio/utils'
25
26 export const uploadState = proxy<{
27 done: number
@@ -314,8 +315,12 @@ async function startUpload(f: File, to: string, resume=0) {
315 const timeout = typeof expires !== 'number' ? 0
316 : (Number(new Date(expires)) - Date.now()) / 1000
317 closeLast?.()
318 + const cancelSub = subscribeKey(uploadState, 'partial', v =>
319 + v >= size && closeLast?.() ) // dismiss dialog as soon as we pass the threshold
320 const msg = t('confirm_resume', "Resume upload?") + ` (${formatPerc(size/f.size)} = ${formatBytes(size)})`
318 - if (!await confirmDialog(msg, { timeout, getClose: x => closeLast=x })) return
321 + const confirmed = await confirmDialog(msg, { timeout, getClose: x => closeLast=x })
322 + cancelSub()
323 + if (!confirmed) return
324 if (uploading !== uploadState.uploading) return // too late
325 resuming = true
326 abortCurrentUpload()