feat(play): a stage with a drawn loader, a file's progress and designed states (#90)

AL
2h ago
+238-50

Closes #90. Part of missing-elements/h5p-toolkit#210.

The play page is what a person sees inside a chat's reply. This makes it look finished: a drawn loader for every wait, a progress bar while a file comes, and designed states for "add your file" and for a problem.

What a person sees now

One stage holds the player's place from the start, in a video's shape, so the reply does not jump when the player arrives. It is in one of five states:

StateWhat is drawn
BuildingA turning ring, "Building the activity in your browser…", "Nothing is sent to a server."
A file coming from the chatThe ring, "Getting your video… 39.8 MB of 230.6 MB", a bar, and "Choose it from your computer instead"
A file neededAn icon, "Add your video", the file's name, "Choose the file", "or drop it here"; the stage is a drop target
A problemAn icon, a heading, one line, and "Open in the build page" where that fixes it
ReadyThe player

Under the stage: the activity's title, its type and the package's size ("Question Set · 1.4 MB"), "Open in the build page" and "Download .h5p". Until the title is known a bar of its size stands there.

For a page that frames this one

Nothing a framing page does today breaks: the messages it gets (status, height, built, needs-files) and files are as before. status has one more state, fetching. New, all optional:

  • ?theme=dark or ?theme=light in the address, read before the first paint by the site's layout, for a chat whose theme is not the system's. A { type: 'theme', theme } message changes it later.
  • { type: 'progress', name, received, total } while the framing page fetches a file the person attached: the page draws the bar and the megabytes.

The page has no background colour of its own, so the chat's shows behind the stage.

Other changes

  • A file can be dropped on the stage while it is asked for.
  • The words a screen reader is told are in one hidden status line, once per state, not with every progress number. The bar is a progressbar with its value.
  • Motion (the ring, the sheen, the bar) only where reduced motion is not asked for; forced colours keep the ring and the bar visible.
  • base.njk: the inline theme script also reads ?theme=, only where the page is in a frame. A page opened by itself keeps the visitor's own theme whatever its address says.

Testing

By hand, since this repository has no page tests: screenshots of every state, framed by a page of another origin at 720 px and 360 px, in light and dark, and the page opened by itself. Looked at each one. A Question Set and an Interactive Video (its video given by the framing page) both reach ready; no console or page error in any run. pnpm build and pnpm typecheck pass.

Found and fixed on the way: at 360 px the stage was wider than the frame; a problem showed "Open in the build page" twice. From the review: the theme in the address is for a framed page only (checked both ways), and a progress message with a number that is not finite or is negative is left.

Not verified

  • Not seen inside ChatGPT yet: the card that frames this page has to send ?theme= and progress first, which is the next step.
  • Chromium only.
  • A real screen reader was not run.

Summary by cubic

Gives the play page a designed stage that holds the player's place in one of five states: building (a drawn loader), a file arriving from the chat with a progress bar and megabytes, a request for a file (chosen or dropped), a problem with the one thing to do, and the player. The reply no longer jumps when the player arrives, and the activity's title, type, size, and actions sit under the stage.

For the page that frames it, nothing breaks: status, height, built, needs-files, and files work as before, and status gains one state, fetching. New, all optional: ?theme=light|dark in the address (or a theme message) and progress messages with name, received, and total while the parent fetches an attached file. A progress message is drawn only while such a file is on its way, and its numbers are held to finite and non-negative. The page's background is transparent, so the chat's shows behind the stage.

Other changes

  • Files can be dropped on the stage while it asks for them.
  • Screen readers are told each state once, in one hidden status line; the progress bar is a progressbar with a value.
  • The loader and bar respect reduced motion and stay visible under forced colours.
  • The inline theme script in base.njk reads ?theme= only in a frame; opened by itself, a page keeps the visitor's own choice.