Presenting: a mode change recounts; coming next follows the talk
Review fix for Task 6. The projector, follow view, remote and presenter view carry data-mode. On a mode change present.js refetches the surface's page for the same slide and step, keeping the stage node in place and replacing the counter and bar; the remote and presenter view reload. "Coming next" on the remote and presenter view is the next slide of the current mode's talk, so the short version never previews a full-only slide. The remote test also checks the picture stays the finished slide across steps.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
9 files changed,
+178
−19
internal/slides/credits/assets.json+1 −1internal/slides/presentation.go+23 −8internal/slides/presenting_position.go+12 −0internal/slides/static/present.js+26 −8internal/slides/templates/present.html+1 −1internal/slides/templates/present_notes.html+1 −0internal/slides/templates/remote.html+1 −1internal/slidestest/present_steps_browser_test.go+57 −0internal/slidestest/present_steps_test.go+56 −0
diff --git a/internal/slides/credits/assets.json b/internal/slides/credits/assets.json| index 293f95f..92618b6 100644 |
| --- a/internal/slides/credits/assets.json |
| +++ b/internal/slides/credits/assets.json |
| @@ -68,7 +68,7 @@ |
| "internal/slides/static/fonts/LiberationSerif-Regular.woff2": "922f544d0eabdf45ecd389b3bb35367e670b736e40851d01e53c150352c012f2", |
| "internal/slides/static/fontsgate.971e476eab8b8588.js": "971e476eab8b8588be520ac38eb823ab19beb2567db734555a7edc40d58567b2", |
| "internal/slides/static/fontshold.876f3d8d396da42f.js": "876f3d8d396da42f81954539f30b7200edfcde719d2920504707822f176a36ab", |
| - "internal/slides/static/present.js": "554d9df41f33ad307a888503e7c571b3bdd3686c6cd9e5b2f7f51f6b9f6d3cb7", |
| + "internal/slides/static/present.js": "40314fa19cd2a822fc860f69190a4571c55dc2097e1104024ebf78ef60ae746d", |
| "internal/slides/static/rastrillo.js": "13a8ca6fa9ac25833f6485ab50a521dff7bd811372025dc5141b96522b60098b", |
| "internal/slides/static/select.js": "e231bad4b964464addfacd52d2260d4bdc0a02938fc033a25fdd9cbeb3671be1", |
| "internal/slides/static/shell.js": "bdc4d635fb8f14ef7089f7f692290baea645b13543be36328e7667fe8aed2caf", |
diff --git a/internal/slides/presentation.go b/internal/slides/presentation.go| index a81ce2e..c0a26fd 100644 |
| --- a/internal/slides/presentation.go |
| +++ b/internal/slides/presentation.go |
| @@ -486,9 +486,11 @@ type surfacePage struct { |
| Counter string |
| // Stepped marks a session with a position, whose slide is drawn at |
| // Step (the surface's data-step), so static/present.js can apply |
| - // the next step in place. |
| + // the next step in place. Mode is the talk being given (data-mode): |
| + // a change of it refreshes the counter and the bar. |
| Stepped bool |
| Step int |
| + Mode string |
| // Announce is what the surface's live region says when it changes |
| // to this slide in place (static/present.js): "Slide 3 of 12: |
| // Revenue". |
| @@ -535,6 +537,8 @@ type presenterPage struct { |
| NextLabel string |
| Next template.HTML |
| HasNext bool |
| + // Mode: see presented. |
| + Mode string |
| NotesLabel string |
| Notes template.HTML |
| @@ -585,10 +589,11 @@ type remotePage struct { |
| NextLabel string |
| Next template.HTML |
| HasNext bool |
| - // Stepped, Step and StepCount: see presented. |
| + // Stepped, Step, StepCount and Mode: see presented. |
| Stepped bool |
| Step int |
| StepCount string |
| + Mode string |
| NotesLabel string |
| Notes template.HTML |
| @@ -755,8 +760,9 @@ func (a *app) renderSurface(w http.ResponseWriter, r *http.Request, d Deck, p Pr |
| page.Total = len(view.Slides) |
| page.Place, page.Places = page.Now, page.Total |
| if reveal != nil { |
| - page.Stepped, page.Step = true, *reveal |
| - page.Place, page.Places = talkPlace(view, positionOf(p).Mode, index) |
| + mode := positionOf(p).Mode |
| + page.Stepped, page.Step, page.Mode = true, *reveal, string(mode) |
| + page.Place, page.Places = talkPlace(view, mode, index) |
| } |
| page.Counter = rastrillo.Tf(r, "slides.present.progress", "n", page.Place, "total", page.Places) |
| page.Announce = rastrillo.Tf(r, "slides.slide.announce", "n", page.Now, "total", page.Total, "title", slideLabel(r, view.Slides[index], page.Now)) |
| @@ -881,6 +887,7 @@ func (a *app) presenterNotes(w http.ResponseWriter, r *http.Request) { |
| shown := presentedFor(r, view, p) |
| page.Now, page.Counter, page.Current = shown.Now, shown.Counter, shown.Current |
| page.Next, page.HasNext, page.Notes = shown.Next, shown.HasNext, shown.Notes |
| + page.Mode = shown.Mode |
| if holder { |
| page.Token = token |
| @@ -947,10 +954,13 @@ type presented struct { |
| // For a session with a position: Stepped, the step it is at (the |
| // page's data-step, so the remote reloads for a step too), and |
| // "step 2 of 4" for a slide with presses, empty for one without. |
| - // The pictures stay the finished slides (P3). |
| + // The pictures stay the finished slides (P3). Mode is the talk being |
| + // given (the page's data-mode, so it reloads when that changes: the |
| + // counter and the slide coming next both depend on it). |
| Stepped bool |
| Step int |
| StepCount string |
| + Mode string |
| } |
| // presentedFor builds them. A slide that will not draw leaves its half |
| @@ -964,12 +974,16 @@ func presentedFor(r *http.Request, view *deck.Deck, p Presentation) presented { |
| } |
| index := clampSlide(p.Slide, count) |
| n, total := index+1, count |
| + next := index + 1 |
| var out presented |
| if p.Positional { |
| var presses int |
| index, out.Step, presses = sessionPlace(view, p) |
| out.Stepped = true |
| - n, total = talkPlace(view, positionOf(p).Mode, index) |
| + mode := positionOf(p).Mode |
| + out.Mode = string(mode) |
| + n, total = talkPlace(view, mode, index) |
| + next = nextInTalk(view, mode, index) |
| if presses > 0 { |
| out.StepCount = rastrillo.Tf(r, "slides.present.step.count", "n", out.Step, "total", presses) |
| } |
| @@ -977,9 +991,9 @@ func presentedFor(r *http.Request, view *deck.Deck, p Presentation) presented { |
| out.Now = index + 1 |
| out.Counter = rastrillo.Tf(r, "slides.present.progress", "n", n, "total", total) |
| out.Current = slideThumbImg(r, view, p, index) |
| - if index+1 < count { |
| + if next >= 0 && next < count { |
| out.HasNext = true |
| - out.Next = slideThumbImg(r, view, p, index+1) |
| + out.Next = slideThumbImg(r, view, p, next) |
| } |
| if s := view.Slides[index]; len(s.Notes) > 0 { |
| out.Notes = slidehtml.Notes(s.Notes) |
| @@ -1081,6 +1095,7 @@ func (a *app) remote(w http.ResponseWriter, r *http.Request) { |
| page.Now, page.Counter, page.Current = shown.Now, shown.Counter, shown.Current |
| page.Next, page.HasNext, page.Notes = shown.Next, shown.HasNext, shown.Notes |
| page.Stepped, page.Step, page.StepCount = shown.Stepped, shown.Step, shown.StepCount |
| + page.Mode = shown.Mode |
| render(w, "remote", page) |
| } |
diff --git a/internal/slides/presenting_position.go b/internal/slides/presenting_position.go| index 2315daf..78487e1 100644 |
| --- a/internal/slides/presenting_position.go |
| +++ b/internal/slides/presenting_position.go |
| @@ -254,6 +254,18 @@ func talkPlace(view *deck.Deck, mode deck.Mode, index int) (int, int) { |
| return n, len(order) |
| } |
| +// nextInTalk is the reader-deck index of the slide after index in the |
| +// talk being given, in mode, or -1 at its end: what "Coming next" |
| +// previews, so the short version never previews a full-only slide. |
| +func nextInTalk(view *deck.Deck, mode deck.Mode, index int) int { |
| + for _, i := range deck.TalkOrder(view, mode) { |
| + if i > index { |
| + return i |
| + } |
| + } |
| + return -1 |
| +} |
| + |
| // pressLabels are the back and forward buttons' words: a press may be |
| // a step rather than a slide on a session with a position, so there |
| // they say Back and Next; a session begun before keeps its own. |
diff --git a/internal/slides/static/present.js b/internal/slides/static/present.js| index ebaf68d..79d0da9 100644 |
| --- a/internal/slides/static/present.js |
| +++ b/internal/slides/static/present.js |
| @@ -176,10 +176,12 @@ |
| return u.href; |
| } |
| - function show(slide, step) { |
| + // again fetches the page even for the slide and step already asked |
| + // for: the talk's mode changed, and with it the counter and the bar. |
| + function show(slide, step, again) { |
| // Slide numbers on the wire are 1-based; anything else is not an |
| // event this page understands and is left alone rather than fetched. |
| - if (!(slide > 0) || (slide === requested && step === requestedStep)) return; |
| + if (!(slide > 0) || (!again && slide === requested && step === requestedStep)) return; |
| requested = slide; |
| requestedStep = step; |
| var mine = ++newest; |
| @@ -258,13 +260,17 @@ |
| var nextStep = nextRoot.getAttribute('data-step'); |
| var drawn = unstepped(nextStage.innerHTML); |
| if (nextStep !== null && shownStep() !== null && drawn === installed) { |
| - reveal(Number(nextStep) || 0); |
| + if ((Number(nextStep) || 0) !== shownStep()) reveal(Number(nextStep) || 0); |
| } else { |
| stage.innerHTML = nextStage.innerHTML; |
| installed = drawn; |
| if (nextStep === null) root.removeAttribute('data-step'); |
| else root.setAttribute('data-step', nextStep); |
| } |
| + // The mode the counter and the bar were drawn for. |
| + var nextMode = nextRoot.getAttribute('data-mode'); |
| + if (nextMode === null) root.removeAttribute('data-mode'); |
| + else root.setAttribute('data-mode', nextMode); |
| if (bar && nextBar) { |
| var fresh = document.importNode(nextBar, true); |
| bar.replaceWith(fresh); |
| @@ -361,9 +367,12 @@ |
| // ever guards the load straight after the reload that wrote it. |
| // |
| // A page that says its step (the remote, on a session with a |
| - // position, data-step) reloads for a step as for a slide. |
| + // position, data-step) reloads for a step as for a slide, and one that |
| + // says its mode (data-mode) for a change of mode: its counter and the |
| + // slide it shows coming next count through the talk being given. |
| var renderedBlackout = root.getAttribute('data-blackout') === 'true'; |
| var renderedStep = root.getAttribute('data-step'); |
| + var renderedMode = root.getAttribute('data-mode'); |
| var reloadKey = 'slides-present-reload:' + window.location.pathname; |
| var reloadedFor = null; |
| try { |
| @@ -371,14 +380,17 @@ |
| window.sessionStorage.removeItem(reloadKey); |
| } catch (err) { /* no storage: see follow */ } |
| - function follow(state, step) { |
| + function follow(state, step, mode) { |
| var slide = Number(state.slide); |
| if (!(slide > 0)) return; |
| var blackout = !!state.blackout; |
| if (renderedStep === null) step = null; |
| + if (renderedMode === null) mode = null; |
| if (slide === displayed && blackout === renderedBlackout && |
| - (step === null || String(step) === renderedStep)) return; |
| - var want = String(slide) + (step === null ? '' : '.' + step) + (blackout ? ':blackout' : ''); |
| + (step === null || String(step) === renderedStep) && |
| + (mode === null || mode === renderedMode)) return; |
| + var want = String(slide) + (step === null ? '' : '.' + step) + |
| + (mode === null ? '' : '@' + mode) + (blackout ? ':blackout' : ''); |
| if (want === reloadedFor) return; |
| try { |
| window.sessionStorage.setItem(reloadKey, want); |
| @@ -409,7 +421,8 @@ |
| appliedSeq = seq; |
| } |
| var step = state.slideId ? Number(state.step) || 0 : null; |
| - if (!stage || !fragmentHref) { follow(state, step); return; } |
| + var mode = state.slideId && state.mode ? String(state.mode) : null; |
| + if (!stage || !fragmentHref) { follow(state, step, mode); return; } |
| // The stream's state is newer than any request still out: none of |
| // them may be applied after it. The slide it names is fetched afresh |
| // unless it is the one already shown. |
| @@ -421,6 +434,11 @@ |
| var slide = Number(state.slide); |
| if (step !== null && requestedStep !== null && slide === displayed) { |
| if (step !== requestedStep) reveal(step); |
| + // Another mode on the same slide: the stage stays as it is, and |
| + // the counter and the bar, which count through the talk being |
| + // given, come afresh from the server (swapFrom keeps the slide). |
| + var drawnMode = root.getAttribute('data-mode'); |
| + if (mode !== null && drawnMode !== null && mode !== drawnMode) show(slide, step, true); |
| return; |
| } |
| show(slide, step); |
diff --git a/internal/slides/templates/present.html b/internal/slides/templates/present.html| index cba575e..6f37ba1 100644 |
| --- a/internal/slides/templates/present.html |
| +++ b/internal/slides/templates/present.html |
| @@ -117,7 +117,7 @@ |
| {{- if .StreamHref}} data-stream="{{.StreamHref}}"{{end}} |
| {{- if .FragmentHref}} data-fragment="{{.FragmentHref}}"{{end}} |
| data-slide="{{.Now}}" |
| - {{- if .Stepped}} data-step="{{.Step}}"{{end}} |
| + {{- if .Stepped}} data-step="{{.Step}}" data-mode="{{.Mode}}"{{end}} |
| data-blackout="{{if .Blackout}}true{{else}}false{{end}}" |
| {{- with .Announce}} data-announce="{{.}}"{{end}} |
| {{- if .Token}} data-remote-token="{{.Token}}"{{end}} |
diff --git a/internal/slides/templates/present_notes.html b/internal/slides/templates/present_notes.html| index 8c7b1b8..1b68958 100644 |
| --- a/internal/slides/templates/present_notes.html |
| +++ b/internal/slides/templates/present_notes.html |
| @@ -110,6 +110,7 @@ |
| drive, which is exactly what the buttons above do too. */}} |
| <div slides-preview data-session="{{.Session}}" |
| data-slide="{{.Now}}" |
| + {{- with .Mode}} data-mode="{{.}}"{{end}} |
| data-blackout="{{if .Blackout}}true{{else}}false{{end}}" |
| {{- if .Token}} data-remote-token="{{.Token}}"{{end}}> |
| <div> |
diff --git a/internal/slides/templates/remote.html b/internal/slides/templates/remote.html| index bec17bc..5352017 100644 |
| --- a/internal/slides/templates/remote.html |
| +++ b/internal/slides/templates/remote.html |
| @@ -61,7 +61,7 @@ |
| <div slides-remote data-session="{{.Session}}" data-remote-token="{{.Controls.Token}}" |
| data-slide="{{.Now}}" |
| - {{- if .Stepped}} data-step="{{.Step}}"{{end}} |
| + {{- if .Stepped}} data-step="{{.Step}}" data-mode="{{.Mode}}"{{end}} |
| data-blackout="{{if .Blackout}}true{{else}}false{{end}}"> |
| <div slides-remote-preview> |
| <div> |
diff --git a/internal/slidestest/present_steps_browser_test.go b/internal/slidestest/present_steps_browser_test.go| index b17ed54..f43b507 100644 |
| --- a/internal/slidestest/present_steps_browser_test.go |
| +++ b/internal/slidestest/present_steps_browser_test.go |
| @@ -161,6 +161,63 @@ func TestBackFromTheNextSlideLandsFullyBuilt(t *testing.T) { |
| } |
| } |
| +// TestAModeChangeRecountsInPlace: switching between the short and the |
| +// full talk on a stepped slide, with a full-only slide later in the |
| +// deck, recounts the projector's counter and bar at once and leaves |
| +// the slide where it is, the same node at the same step; the phone |
| +// recounts too. |
| +func TestAModeChangeRecountsInPlace(t *testing.T) { |
| + st := newStepsTalk(t) |
| + counter := func(want string) chromedp.Action { |
| + return waitFor(`(document.querySelector('[slides-counter]')?.textContent ?? '').includes('` + want + `')`) |
| + } |
| + st.rig.Run( |
| + chromedp.Navigate(st.rig.Origin+"/p/"+st.session+"?t="+url.QueryEscape(st.token)), |
| + chromedp.WaitVisible(`[slides-stage] [slides-slide]`, chromedp.ByQuery), |
| + waitWaiting("4"), |
| + counter("1 / 3"), |
| + chromedp.Click(`[slides-bar] button[slides-op="next"]`, chromedp.ByQuery), |
| + waitWaiting("3"), |
| + chromedp.Evaluate(markSection, nil), |
| + ) |
| + |
| + var max, mode string |
| + for _, want := range []struct{ op, counter, max, mode, step string }{ |
| + {"mode", "1 / 4", "4", "full", "1"}, |
| + {"next", "1 / 4", "4", "full", "2"}, |
| + {"mode", "1 / 3", "3", "core", "2"}, |
| + } { |
| + st.press(t, want.op) |
| + st.rig.Run( |
| + counter(want.counter), |
| + waitFor(`document.querySelector('[slides-surface]').getAttribute('data-step') === '`+want.step+`'`), |
| + chromedp.Evaluate(`document.querySelector('[slides-progress]').getAttribute('max')`, &max), |
| + chromedp.Evaluate(`document.querySelector('[slides-surface]').getAttribute('data-mode')`, &mode), |
| + ) |
| + got := st.stage(t) |
| + if !got.Same || got.Slide != "1" || max != want.max || mode != want.mode { |
| + t.Errorf("after %s: same node %v, data-slide %q, progress max %q, data-mode %q; want the same node on slide 1, max %s, %s", |
| + want.op, got.Same, got.Slide, max, mode, want.max, want.mode) |
| + } |
| + } |
| + |
| + var text string |
| + st.rig.Run( |
| + chromedp.Navigate(st.rig.Origin+"/p/"+st.session+"/remote?t="+url.QueryEscape(st.token)), |
| + chromedp.WaitVisible(`[slides-remote]`, chromedp.ByQuery), |
| + counter("1 / 3"), |
| + ) |
| + st.press(t, "mode") |
| + st.rig.Run( |
| + counter("1 / 4"), |
| + waitFor(`document.querySelector('[slides-remote]')?.getAttribute('data-mode') === 'full'`), |
| + chromedp.Evaluate(`document.querySelector('[slides-counter]').textContent`, &text), |
| + ) |
| + if !strings.Contains(text, "1 / 4") { |
| + t.Errorf("the remote after a switch to the full talk says %q, want 1 / 4", text) |
| + } |
| +} |
| + |
| // TestReducedMotionAppears: with the deck set to fade, what arrives |
| // fades and is unmarked once it has; with reduced motion asked for it |
| // simply appears. |
diff --git a/internal/slidestest/present_steps_test.go b/internal/slidestest/present_steps_test.go| index 331361a..815d089 100644 |
| --- a/internal/slidestest/present_steps_test.go |
| +++ b/internal/slidestest/present_steps_test.go |
| @@ -195,9 +195,18 @@ func TestRemoteSaysWhichStep(t *testing.T) { |
| session, token := startPresenting(t, a, stepsDeck(t, a, cookies), cookies) |
| remote := "/p/" + session + "/remote?t=" + url.QueryEscape(token) |
| + // The picture of the slide on screen is the finished slide whatever |
| + // the step (P3): the same address at step 0 and at step 2. |
| + finished := "/p/" + session + "/slides/steps.svg" |
| + if got, _ := pictures(mustGet(t, a, remote, http.StatusOK, nil).Body.String()); got != finished { |
| + t.Errorf("the remote at step 0 pictures %q, want %q", got, finished) |
| + } |
| press(t, a, session, token, op(t, "next"), nil) |
| press(t, a, session, token, op(t, "next"), nil) |
| page := mustGet(t, a, remote, http.StatusOK, nil).Body.String() |
| + if got, _ := pictures(page); got != finished { |
| + t.Errorf("the remote at step 2 pictures %q, want the finished slide, %q", got, finished) |
| + } |
| if !strings.Contains(page, "step 2 of 4") { |
| t.Errorf("the remote at step 2 of the steps slide does not say step 2 of 4:\n%s", page) |
| } |
| @@ -216,3 +225,50 @@ func TestRemoteSaysWhichStep(t *testing.T) { |
| t.Errorf("the remote names a step on a slide with no presses:\n%s", page) |
| } |
| } |
| + |
| +var thumbSrc = regexp.MustCompile(`<img slides-thumb-img src="([^"]+)"`) |
| + |
| +// pictures is the remote's or the presenter view's two pictures: the |
| +// slide on screen and the one coming next ("" when there is none). |
| +func pictures(page string) (current, next string) { |
| + m := thumbSrc.FindAllStringSubmatch(page, -1) |
| + if len(m) > 0 { |
| + current = m[0][1] |
| + } |
| + if len(m) > 1 { |
| + next = m[1][1] |
| + } |
| + return current, next |
| +} |
| + |
| +// TestComingNextIsInTheTalkBeingGiven: the slide the remote and the |
| +// presenter view show coming next is the next one of the talk being |
| +// given, so the short version never previews a full-only slide, and |
| +// switching to the full version brings it in; the counter counts the |
| +// same talk. |
| +func TestComingNextIsInTheTalkBeingGiven(t *testing.T) { |
| + a := newApp(t) |
| + cookies := signedIn(t, a, allowedAddress) |
| + session, token := startPresenting(t, a, stepsDeck(t, a, cookies), cookies) |
| + for range 5 { |
| + press(t, a, session, token, op(t, "next"), nil) |
| + } |
| + for _, c := range []struct{ mode, next, counter string }{ |
| + {"core", "last", "2 / 3"}, |
| + {"full", "extra", "2 / 4"}, |
| + } { |
| + if c.mode == "full" { |
| + press(t, a, session, token, op(t, "mode"), nil) |
| + } |
| + for _, screen := range []string{"remote", "notes"} { |
| + page := mustGet(t, a, "/p/"+session+"/"+screen+"?t="+url.QueryEscape(token), http.StatusOK, nil).Body.String() |
| + current, next := pictures(page) |
| + if current != "/p/"+session+"/slides/plain.svg" || next != "/p/"+session+"/slides/"+c.next+".svg" { |
| + t.Errorf("%s in %s mode: pictures %q then %q, want plain then %s", screen, c.mode, current, next, c.next) |
| + } |
| + if !strings.Contains(page, c.counter) || !strings.Contains(page, `data-mode="`+c.mode+`"`) { |
| + t.Errorf("%s in %s mode does not say %s and data-mode=%q", screen, c.mode, c.counter, c.mode) |
| + } |
| + } |
| + } |
| +} |