Skip to content

Commit d3fae69

Browse files
committed
fix(play): the page's own fetch of several files says which is coming too, and the progress bars name it
1 parent be732ae commit d3fae69

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

‎src/h5p/play/play-page.ts‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -386,10 +386,11 @@ function fetching(name: string, received: number, total: number, index = 1, coun
386386
note.textContent = 'From the chat to your browser, nowhere else.'
387387
const done = total > 0 ? Math.min(100, Math.round(received / total * 100)) : 0
388388
progress.hidden = total <= 0
389+
progress.setAttribute('aria-label', count > 1 ? `Getting file ${index} of ${count}` : 'Getting the file')
389390
progress.setAttribute('aria-valuenow', String(done))
390391
progressBar.style.setProperty('--done', `${done}%`)
391392
instead.hidden = false
392-
if (main.dataset.state !== 'fetching') show('fetching', `Getting your ${what} from the chat.`)
393+
if (main.dataset.state !== 'fetching') show('fetching', count > 1 ? `Getting your ${count} files from the chat.` : `Getting your ${what} from the chat.`)
393394
}
394395

395396
/** Files given, by the person (`mine`) or by the parent: the activity is built once none is missing. */
@@ -540,9 +541,10 @@ function fetchToKeep(): void {
540541
* Files fetched by this page from their addresses, by their paths in the source, counted as they
541542
* come, ten times a second at most. The browser keeps each as a Blob, which it may hold on disk.
542543
*/
543-
async function fetched(from: Record<string, string>, signal: AbortSignal, count: (name: string, received: number, total: number) => void): Promise<File[]> {
544+
async function fetched(from: Record<string, string>, signal: AbortSignal, count: (name: string, received: number, total: number, index: number, of: number) => void): Promise<File[]> {
544545
const files: File[] = []
545-
for (const [path, address] of Object.entries(from)) {
546+
const entries = Object.entries(from)
547+
for (const [index, [path, address]] of entries.entries()) {
546548
const response = await fetch(address, { signal })
547549
if (!response.ok || !response.body) throw new Error(`the chat answered ${response.status}`)
548550
const total = Number(response.headers.get('content-length')) || 0
@@ -551,7 +553,7 @@ async function fetched(from: Record<string, string>, signal: AbortSignal, count:
551553
const counted = response.body.pipeThrough(new TransformStream<Uint8Array, Uint8Array>({
552554
transform(chunk, controller) {
553555
received += chunk.byteLength
554-
if (performance.now() - shown > 100) { shown = performance.now(); count(baseName(path), received, total) }
556+
if (performance.now() - shown > 100) { shown = performance.now(); count(baseName(path), received, total, index + 1, entries.length) }
555557
controller.enqueue(chunk)
556558
},
557559
}))
@@ -670,6 +672,7 @@ function keepCount(name: string, received: number, total: number, index = 1, cou
670672
if (!bringing) return
671673
const what = count > 1 ? 'files' : previewed.length === 1 ? called(name || previewed[0]!) : 'file'
672674
keepLabel.textContent = `Getting your ${what} for the download…${count > 1 ? ` ${index} of ${count},` : ''} ${sized(received)}${total > 0 ? ` of ${sized(total)}` : ''}`
675+
keepProgress.setAttribute('aria-label', count > 1 ? `Getting file ${index} of ${count} for the download` : 'Getting the file for the download')
673676
if (total > 0) {
674677
const done = Math.min(100, Math.round(received / total * 100))
675678
delete keepProgress.dataset.indeterminate

0 commit comments

Comments
 (0)