fix start workout timer on document ready

Commit
ec271217f5013641ca8da01fd4e97fdcb212e08e
Author
Marius Peter <dev@marius-peter.com>
Author date
Committer
Marius Peter <dev@marius-peter.com>
Committer date
Changed files
lib/web/workout_client.ml
index 6abdac7d..0f64ca56 100644..100644
@@ -434,5 +434,13 @@
434 434 a no-JS visitor keeps every fallback. *)
435 435 document##.documentElement##setAttribute
436 436 (Js.string "data-hito-js") (Js.string "on");
437 Added: (* Retry startup after the document is ready. This is idempotent because
438 Added: [start_timer] clears any prior interval before it reads the current timer. *)
439 Added: Dom_html.addEventListener document Dom_html.Event.domContentLoaded
440 Added: (Dom_html.handler (fun _ ->
441 Added: start_timer ();
442 Added: Js._true))
443 Added: Js._false
444 Added: |> ignore;
437 445 start_timer ();
438 446 dismiss_toast ()
test/test_web.ml
index 608e7b3a..c1e33fac 100644..100644
@@ -826,7 +826,11 @@
826 826 (contains ~substring:"data-hito-workout-timer" page);
827 827 Alcotest.(check bool)
828 828 "carries the workout start epoch" true
829 Removed: (contains ~substring:"data-started=" page) );
829 Added: (contains ~substring:"data-started=" page);
830 Added: let client_script = body (get c "/assets/workout-client.js") in
831 Added: Alcotest.(check bool)
832 Added: "serves the DOM-ready timer startup hook" true
833 Added: (contains ~substring:"DOMContentLoaded" client_script) );
830 834 ( "cancelling a workout without a CSRF token leaves the view cleanly",
831 835 `Quick,
832 836 fun () ->