refactor(viewer): dedupe shared viewer chrome (pager + back-link)
Description
Several list/detail pages now carry their own copy of the same viewer chrome. Two pieces are
duplicated on main and should be consolidated into a single source of truth.
1. Client-side pager (Repositories + Sessions)
The Repositories page (#1382 / #1322) and the Sessions list page (#1377 / #1323) each shipped their own copy of the same pager:
- JS —
internal/viewer/static/repos.js(~120 lines, search + pager) andinternal/viewer/static/sessions.js(~93 lines, pager only) reimplement the samepageList/render/ ellipsis-window / step-disabling / focus-management logic. - CSS —
internal/viewer/static/style.csscarries two identical rule sets differing only in prefix:.repos-page .{pagination,page-step,page-number,page-numbers,page-gap, …}and.sessions-page .{…}(13 selectors each). - Template markup — the pager
<nav class="pagination">…</nav>block intemplates/repos.htmlandtemplates/sessions.htmlis identical apart from its ids.
2. Back-link control (Sessions list + Session detail)
The Sessions list (#1377 / #1323) and the Session detail header (#1384 / #1324) each override
.back-link into the same icon-box treatment:
internal/viewer/static/style.csshas a base.back-link(with a now-dead::beforeCSS arrow) plus two near-identical scoped overrides —.sessions-page .back-linkand.session-page .back-link(each with:hover,::before { content: none }, andsvgsizing).- Both templates already render the same markup:
<a class="back-link" …>{{icon "chevron-left"}}</a>.
Scope / approach
Pager
- CSS: promote the duplicated pager rules to unscoped
.pagination,.page-step,.page-number,.page-numbers,.page-gap(drop the.repos-page/.sessions-pageprefixes). Keep only genuinely page-specific rules scoped. - JS: extract a shared
internal/viewer/static/pager.jsthat exposes a small global initializer (e.g.window.ocrPager({ table, pager, numbers, pageSize, filter })), and add it to the//go:embeddirective inserver.go.repos.jskeeps its search input and calls the shared pager with afilter;sessions.jscalls it without one. Stay with plain<script src>(no ES modules) so it remains CSP-safe and consistent with the other viewer scripts; loadpager.jsbefore the page script. - Template: extract the pager
<nav>into a shared partial (likeapp-header), parameterized by id prefix andaria-label, used by both pages.
Back-link
- Fold the icon-box treatment into the base
.back-linkrule (SVG-based): remove the dead::beforeCSS arrow, add base.back-link svgsizing, and keep the hover/focus states once. Then delete the two per-page overrides (.sessions-page .back-link*,.session-page .back-link*). The templates already render{{icon "chevron-left"}}, so no template change is needed. Keep any genuinely page-specific bit scoped (there is likely none).
Tests
- Update the existing pager tests to the deduplicated structure —
TestReposJS_PagerContract,TestSessionsJS_PagerContract,TestReposCSS_PagerStaysHiddenUntilScripted,TestSessionsCSS_PagerStaysHiddenUntilScripted(the CSS guard moves to the unscoped.pagination[hidden]selector; the JS contract moves topager.js).
Out of scope
- No behavior or visual change — both the pager and the back buttons must look and behave exactly as they do today (10 per page, ellipsis window, hidden-until-scripted, focus handling; back buttons unchanged on both pages).
- No move to a bundler or ES modules.
Acceptance Criteria
- [ ] Pager: one shared
pager.js, one set of unscoped pager CSS rules, and one pager template partial.repos.js/sessions.jsno longer duplicate the pager logic or styles. - [ ] Repositories and Sessions pages paginate identically to before (incl. search on the repos page), pager stays hidden until scripted, focus management preserved.
- [ ] Back-link: a single base
.back-linkrule drives both pages; the per-page.sessions-page/.session-pageback-link overrides and the dead::beforearrow are gone; both back buttons look and behave as they do today. - [ ] No CSP regression (external scripts only; no inline
<script>). - [ ] Tests pass (
make test) and code check passes (make check).
Context
Part of #1319. The pager copies landed via #1382 (#1322) and #1377 (#1323); the back-link overrides landed via #1377 (#1323) and #1384 (#1324). Each PR independently mirrored the same chrome — this issue merges them into one source of truth so the patterns aren't copied a fourth time.
AI disclosure: The scope and decisions are my own. An AI assistant (Claude Opus 4.8) was used only to polish the English wording.
I'd like to work on this.
I'd like to work on this.
ok