Skip to content

Commit 85e73e1

Browse files
committed
fix(play): the parent is told the missing files once per set of names (#88)
A parent that answered each needs-files with the same files, some of them, was asked again with every answer, without end.
1 parent 62e503f commit 85e73e1

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ const chosen = new Map<string, File>()
4141
let packageUrl: string | null = null
4242
/** Counts builds, so that one overtaken by a newer one shows nothing. */
4343
let builds = 0
44+
/** The missing names the parent was last told, so that it is told again only when they change. */
45+
let told = ''
4446

4547
const framed = window.parent !== window
4648
const toParent = (message: Record<string, unknown>): void => { if (framed) window.parent.postMessage({ source: 'h5p-play', ...message }, '*') }
@@ -76,7 +78,11 @@ function filesFor(paths: string[]): { files: Record<string, File>, missing: stri
7678
return matched
7779
}
7880

79-
/** Asks for the files still missing, by their names, and tells the parent, which may have them. */
81+
/**
82+
* Asks for the files still missing, by their names, and tells the parent, which may have them. The
83+
* parent is told once for a set of names: one that answers each time with the same files, some of
84+
* them or none that match, would otherwise be asked again with every answer, without end.
85+
*/
8086
function ask(missing: string[]): void {
8187
const names = missing.map(baseName)
8288
const listed = new Intl.ListFormat('en-GB', { type: 'conjunction' }).format(names)
@@ -87,6 +93,9 @@ function ask(missing: string[]): void {
8793
say(chosen.size
8894
? `Still needed: ${listed}.`
8995
: `This activity uses ${one ? 'a file' : 'files'} of yours: ${listed}. Choose ${one ? 'it' : 'them'} from your computer; ${one ? 'it stays' : 'they stay'} in your browser.`, 'asking')
96+
const missingNow = names.join('\n')
97+
if (missingNow === told) return
98+
told = missingNow
9099
toParent({ type: 'needs-files', names })
91100
}
92101

0 commit comments

Comments
 (0)