oficina / docs Public

Docs list: the newest five as pages, everything older as rows

Paul, on the preview: recents as document previews, then a list. The
shelf is the first five rows across the recency groups (splitRecent);
the rest stay grouped in rastrillo's rows with a small sheet each.
Search results are rows. A shelf page is one link from paper to date:
the overlay stretched from the line-clamped title missed the paper in
Safari, so the previews could not be clicked. On a phone the shelf is
a row you swipe.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Paul Campbell pushed by paul@keymail.dev d182fc26b6e282f9ed2d3b90aca2b3387fafd31e parent 72c8d9b
3 files changed, +191 −119
  • internal/docs/handlers.go +28 −2
  • internal/docs/recent_test.go +46 −0
  • internal/docs/views/list.html +117 −117

CI passed — run details

diff --git a/internal/docs/handlers.go b/internal/docs/handlers.go
index 4770247..03ead8b 100644
--- a/internal/docs/handlers.go
+++ b/internal/docs/handlers.go
@@ -142,7 +142,11 @@ type listPage struct {
// as the editor a reader could type into. (Re-review, finding 3.)
CanCreate bool
- Title string
+ Title string
+ // Recent is the newest few documents, shown as their first pages
+ // across the top of the list; Groups is everything after them, as
+ // rows. See splitRecent.
+ Recent []docRow
Groups []docGroup
EmptyTitle string
EmptyBody string
@@ -345,7 +349,7 @@ func (h *handlers) list(w http.ResponseWriter, r *http.Request) {
return
}
data.PartialCatalog = h.partialCatalog(r)
- data.Groups = groupByRecency(r, time.Now().UTC(), docs, h.thumbnailer(r.Context()), who.PersonID)
+ data.Recent, data.Groups = splitRecent(groupByRecency(r, time.Now().UTC(), docs, h.thumbnailer(r.Context()), who.PersonID), recentShelf)
if err := h.render.page(w, r, "list", data); err != nil {
h.logger.Error("docs: render list", "err", err)
h.fail(w, r, h.internalFailureStatus(), failStatus)
@@ -1088,6 +1092,28 @@ func groupByRecency(r *http.Request, now time.Time, docs []*Document, thumb func
return groups
}
+// recentShelf is how many of the newest documents the list shows as
+// pages rather than rows: one row of them on a desktop column.
+const recentShelf = 5
+
+// splitRecent takes the first n rows across groups, in order, for the
+// shelf of pages at the top of the list, and returns the groups that
+// remain for the rows below it. A group whose rows all went to the
+// shelf is dropped; one split by the shelf keeps its label, so the
+// rows under "Today" are still today's.
+func splitRecent(groups []docGroup, n int) ([]docRow, []docGroup) {
+ var recent []docRow
+ var rest []docGroup
+ for _, g := range groups {
+ take := min(n-len(recent), len(g.Rows))
+ recent = append(recent, g.Rows[:take]...)
+ if take < len(g.Rows) {
+ rest = append(rest, docGroup{Label: g.Label, Rows: g.Rows[take:]})
+ }
+ }
+ return recent, rest
+}
+
// recencyBucket returns a stable bucket key and the catalog key for
// its label, comparing calendar days in UTC — Document.CreatedAt and
// UpdatedAt are both stored in UTC (Store.Create), and there is no
diff --git a/internal/docs/recent_test.go b/internal/docs/recent_test.go
new file mode 100644
index 0000000..ad5a422
--- /dev/null
+++ b/internal/docs/recent_test.go
@@ -0,0 +1,46 @@
+package docs
+
+import (
+ "reflect"
+ "testing"
+)
+
+// The shelf takes the newest rows across groups, in order; a group the
+// shelf emptied is dropped, and one it split keeps its label.
+func TestSplitRecent(t *testing.T) {
+ rows := func(titles ...string) []docRow {
+ var out []docRow
+ for _, s := range titles {
+ out = append(out, docRow{Title: s})
+ }
+ return out
+ }
+ titles := func(rs []docRow) []string {
+ var out []string
+ for _, r := range rs {
+ out = append(out, r.Title)
+ }
+ return out
+ }
+ groups := []docGroup{
+ {Label: "Today", Rows: rows("a", "b")},
+ {Label: "Yesterday", Rows: rows("c")},
+ {Label: "Earlier", Rows: rows("d", "e", "f", "g")},
+ }
+
+ recent, rest := splitRecent(groups, 5)
+ if got := titles(recent); !reflect.DeepEqual(got, []string{"a", "b", "c", "d", "e"}) {
+ t.Errorf("shelf = %v", got)
+ }
+ if len(rest) != 1 || rest[0].Label != "Earlier" || !reflect.DeepEqual(titles(rest[0].Rows), []string{"f", "g"}) {
+ t.Errorf("rows after the shelf = %+v", rest)
+ }
+
+ recent, rest = splitRecent(groups[:1], 5)
+ if len(recent) != 2 || rest != nil {
+ t.Errorf("fewer documents than the shelf holds: shelf %d, groups %+v", len(recent), rest)
+ }
+ if recent, rest = splitRecent(nil, 5); recent != nil || rest != nil {
+ t.Errorf("no documents: shelf %v, groups %v", recent, rest)
+ }
+}
diff --git a/internal/docs/views/list.html b/internal/docs/views/list.html
index f1ce5bf..5a7cc3b 100644
--- a/internal/docs/views/list.html
+++ b/internal/docs/views/list.html
@@ -60,12 +60,22 @@
which is what an empty document, and a document whose structure
could not be read, both get. */}}
{{define "thumb"}}<span docs-thumb aria-hidden="true">{{if .Bars}}<svg viewBox="0 0 {{.W}} {{.H}}" preserveAspectRatio="xMidYMin slice">{{range .Bars}}<rect x="{{.X}}" y="{{.Y}}" width="{{.W}}" height="{{.H}}"/>{{end}}</svg>{{end}}</span>{{end}}
-{{/* tile — one document on the shelf. */}}
-{{define "tile"}}<li docs-tile>
- <span docs-tile-title><a href="{{.Href}}">{{.Title}}</a></span>
+{{/* tile — one of the newest documents, as its first page. The whole
+ tile is one link, paper, title and date: an overlay stretched from
+ the title missed the paper in Safari, where the line-clamped title
+ box clipped it. The link's name is its text, title first. */}}
+{{define "tile"}}<li><a docs-tile href="{{.Href}}">
+ <span docs-tile-title>{{.Title}}</span>
{{template "thumb" .Thumb}}
<span docs-tile-meta><span docs-row-when>{{.When}}</span>{{if .SharedNote}}<span docs-row-shared>{{.SharedNote}}</span>{{end}}</span>
- </li>{{end}}
+ </a></li>{{end}}
+{{/* row — every older document, and every search result: rastrillo's
+ row, whose title link it stretches over the whole row itself. */}}
+{{define "row"}}<div rst-row>
+ {{template "thumb" .Thumb}}
+ <span rst-row-main><a href="{{.Href}}">{{.Title}}</a></span>
+ {{if .SharedNote}}<span rst-muted docs-row-shared>{{.SharedNote}}</span>{{end}}<span docs-row-when>{{.When}}</span>
+ </div>{{end}}
{{define "content"}}<style>
/* The desk. The list is the person's documents laid out as the paper
they are, so the page under them is a desk rather than a form: the
@@ -197,79 +207,50 @@
white-space: nowrap;
box-shadow: 0 1px 0 rgb(255 255 255 / 0.18) inset, 0 6px 16px -6px color-mix(in oklab, var(--rst-accent) 70%, transparent);
}
- /* The shelf: every document as its own first page, side by side,
- each page --docs-tile wide. The recency groups (spec §6.4) sit
- side by side on the same shelf rather than each taking a band of
- the screen, each with its heading over its own pages: "Today",
- two pages, "Yesterday", one, and so on along the row, wrapping
- like words. A group with more pages than fit on one line takes
- the whole width and wraps inside itself. */
- [docs-list] {
- --docs-tile: 10.5rem;
- --docs-tile-gap: var(--rst-sp-5);
- }
- [docs-groups] {
- display: flex;
- flex-wrap: wrap;
- gap: var(--rst-sp-6) calc(var(--docs-tile-gap) * 2);
- }
- [docs-group] {
- flex: 0 1 auto;
- min-inline-size: 0;
- }
- /* A group's heading is a quiet label over its pages: sentence case,
- the muted ink, weight doing the work rather than capitals, with a
- hairline running out to the group's edge so the pages under it
- read as one run. */
- [docs-group-label] {
- display: flex;
- align-items: center;
- gap: var(--rst-sp-3);
- margin: 0 0 var(--rst-sp-4);
- font-size: var(--rst-fs-sm, 0.875rem);
- font-weight: 600;
- color: var(--rst-text-muted);
- white-space: nowrap;
- }
- [docs-group-label]::after {
- content: "";
- flex: 1 1 auto;
- min-inline-size: var(--rst-sp-5);
- border-block-start: 1px solid light-dark(rgb(23 32 60 / 0.12), rgb(255 255 255 / 0.12));
- }
+ /* The shelf: the newest documents as their own first pages, one
+ row of them across the column (recentShelf, handlers.go). On a
+ phone it is a row you swipe, two and a bit pages wide, so the
+ list below it is still on the first screen. */
[docs-shelf] {
- display: flex;
- flex-wrap: wrap;
- gap: var(--rst-sp-6) var(--docs-tile-gap);
- margin: 0;
+ display: grid;
+ grid-template-columns: repeat(5, minmax(0, 1fr));
+ gap: var(--rst-sp-5);
+ margin: 0 0 var(--rst-sp-6);
padding: 0;
list-style: none;
}
- [docs-shelf] > [docs-tile] {
- inline-size: var(--docs-tile);
- }
- /* Two pages to a row on a phone, edge to edge of the column. */
- @media (max-width: 30rem) {
- [docs-list] {
- --docs-tile-gap: var(--rst-sp-4);
+ @media (max-width: 48rem) {
+ [docs-shelf] {
+ grid-template-columns: none;
+ grid-auto-flow: column;
+ grid-auto-columns: 40%;
+ gap: var(--rst-sp-4);
+ overflow-x: auto;
+ overscroll-behavior-x: contain;
+ scroll-snap-type: x mandatory;
+ scrollbar-width: none;
+ /* Room for the pages' shadows and their lift inside the
+ scroller, which clips both. */
+ margin-inline: calc(var(--rst-sp-4) * -1);
+ padding: var(--rst-sp-2) var(--rst-sp-4) var(--rst-sp-4);
+ scroll-padding-inline: var(--rst-sp-4);
}
- [docs-group] {
- flex-basis: 100%;
- }
- [docs-shelf] > [docs-tile] {
- inline-size: calc((100% - var(--docs-tile-gap)) / 2);
+ [docs-shelf] > li {
+ scroll-snap-align: start;
}
}
- /* One document. The title link is stretched over the whole tile by
- its ::after, the same overlay rastrillo's rows use, so the paper,
- the title and the date are all one target without nesting
- anything interactive inside the link. */
[docs-tile] {
- position: relative;
display: flex;
flex-direction: column;
gap: var(--rst-sp-1);
min-inline-size: 0;
+ color: var(--rst-text);
+ text-decoration: none;
+ border-radius: var(--rst-radius-sm);
+ }
+ [docs-tile]:focus-visible {
+ outline: 2px solid var(--rst-accent);
+ outline-offset: 6px;
}
[docs-tile-title] {
order: 2;
@@ -284,23 +265,6 @@
line-clamp: 2;
overflow: hidden;
}
- [docs-tile-title] a {
- color: var(--rst-text);
- text-decoration: none;
- }
- [docs-tile-title] a::after {
- content: "";
- position: absolute;
- inset: -6px;
- border-radius: var(--rst-radius-sm);
- }
- [docs-tile-title] a:focus-visible {
- outline: none;
- }
- [docs-tile-title] a:focus-visible::after {
- outline: 2px solid var(--rst-accent);
- outline-offset: 2px;
- }
[docs-tile-meta] {
order: 3;
display: flex;
@@ -311,24 +275,21 @@
}
/* [docs-thumb] holds a real rendering of the document's page one:
the <svg> inside it is the line boxes the PDF exporter's own
- layout placed, through export.PageOne (see preview.go). At shelf
- size it reads as the page it is, margins and all, so the box is
- the page's own aspect (612 by 792, the viewBox) and the paper is
- the literal white a document always is (spec §10.2), in either
- theme. An empty document is the same sheet with nothing on it. */
+ layout placed, through export.PageOne (see preview.go), in the
+ page's own coordinates (612 by 792, the viewBox), margins and
+ all. The paper is the literal white a document always is (spec
+ §10.2), in either theme. An empty document is the same sheet with
+ nothing on it. */
[docs-thumb] {
- order: 1;
display: block;
- inline-size: 100%;
+ flex: none;
aspect-ratio: 612 / 792;
- border-radius: 3px;
+ border-radius: 2px;
background: #ffffff;
overflow: hidden;
box-shadow:
- 0 0 0 1px light-dark(rgb(23 32 60 / 0.07), rgb(255 255 255 / 0.06)),
- 0 1px 2px rgb(23 32 60 / 0.08),
- 0 10px 24px -12px light-dark(rgb(23 32 60 / 0.28), rgb(0 0 0 / 0.7));
- transition: transform 180ms cubic-bezier(.2, .7, .2, 1), box-shadow 180ms ease;
+ 0 0 0 1px light-dark(rgb(23 32 60 / 0.10), rgb(255 255 255 / 0.08)),
+ 0 1px 2px rgb(23 32 60 / 0.08);
}
[docs-thumb] > svg {
display: block;
@@ -342,29 +303,71 @@
[docs-thumb] rect {
fill: #b9c0cc;
}
+ /* On the shelf the page is the tile: full width, lying on the desk. */
+ [docs-tile] [docs-thumb] {
+ order: 1;
+ inline-size: 100%;
+ border-radius: 3px;
+ box-shadow:
+ 0 0 0 1px light-dark(rgb(23 32 60 / 0.07), rgb(255 255 255 / 0.06)),
+ 0 1px 2px rgb(23 32 60 / 0.08),
+ 0 10px 24px -12px light-dark(rgb(23 32 60 / 0.28), rgb(0 0 0 / 0.7));
+ transition: transform 180ms cubic-bezier(.2, .7, .2, 1), box-shadow 180ms ease;
+ }
/* Picking a page up: it lifts and takes the accent's edge. The
motion answers the pointer, and is dropped for reduced motion,
where the edge alone says the same thing. */
[docs-tile]:hover [docs-thumb],
- [docs-tile]:has(a:focus-visible) [docs-thumb] {
+ [docs-tile]:focus-visible [docs-thumb] {
transform: translateY(-4px);
box-shadow:
0 0 0 1.5px var(--rst-accent),
0 2px 4px rgb(23 32 60 / 0.08),
0 18px 32px -14px light-dark(rgb(23 32 60 / 0.35), rgb(0 0 0 / 0.8));
}
- [docs-tile]:hover [docs-tile-title] a {
+ [docs-tile]:hover [docs-tile-title] {
color: var(--rst-accent);
}
@media (prefers-reduced-motion: reduce) {
- [docs-thumb] {
+ [docs-tile] [docs-thumb] {
transition: none;
}
[docs-tile]:hover [docs-thumb],
- [docs-tile]:has(a:focus-visible) [docs-thumb] {
+ [docs-tile]:focus-visible [docs-thumb] {
transform: none;
}
}
+ /* The rows: everything older than the shelf, grouped by recency
+ (spec §6.4), and every search result. rastrillo's list and row,
+ with a small sheet of the page at the start of each. rastrillo
+ already stretches the title link over the whole row ([rst-row]
+ position: relative, [rst-row-main] > a::after inset: 0) and tints
+ it on hover; nothing of ours restates that. */
+ [docs-list] [rst-list] {
+ border-radius: var(--rst-radius);
+ box-shadow: 0 1px 2px light-dark(rgb(23 32 60 / 0.05), transparent);
+ }
+ [docs-list] [rst-row] {
+ gap: var(--rst-sp-3);
+ }
+ [rst-row] [docs-thumb] {
+ inline-size: 26px;
+ }
+ /* A group's heading inside the list: sentence case, the muted ink,
+ weight doing the work rather than capitals. */
+ [docs-group-label] {
+ margin: 0;
+ padding: var(--rst-sp-4) var(--rst-sp-4) var(--rst-sp-2);
+ font-size: var(--rst-fs-sm, 0.875rem);
+ font-weight: 600;
+ color: var(--rst-text-muted);
+ }
+ [docs-row-when] {
+ flex: none;
+ color: var(--rst-text-muted);
+ font-size: var(--rst-fs-sm);
+ font-variant-numeric: tabular-nums;
+ }
/* The way back out of a result page, under the results rather than
in the header: it is about the list being shown, not about the
controls that produced it. */
@@ -401,19 +404,17 @@
</div>
</header>
{{if .PartialCatalog}}{{template "callout" (dict "Body" .PartialCatalog "Tone" "warning")}}{{end}}
-{{/* Searching renders a ranked, UNGROUPED result shelf. Recency
+{{/* Searching renders a ranked, UNGROUPED list of rows. Recency
grouping is what an unfiltered list is for; grouping ranked
- results under "Today" and "Earlier" would order the same pages
- twice by two different rules and show only the second.
-
- Each tile's link comes first in the markup and the paper is put
- back above it by order: so a screen reader, and the tab order,
- meet the title first, and the page's picture is decoration. */}}
+ results under "Today" and "Earlier" would order the same rows
+ twice by two different rules and show only the second. And a
+ result is found by its title, so the shelf of pages, which is
+ about what was worked on last, has no place here. */}}
{{if .Searching}}
{{if .Results}}
-<ul docs-shelf>
- {{range .Results}}{{template "tile" .}}{{end}}
-</ul>
+<div rst-list>
+ {{range .Results}}{{template "row" .}}{{end}}
+</div>
{{else}}
<div rst-empty>
<h2 rst-empty-title>{{.NoResultsHead}}</h2>
@@ -421,17 +422,16 @@
</div>
{{end}}
<p docs-search-clear><a href="/">{{.ClearLabel}}</a></p>
-{{else if .Groups}}
-<div docs-groups>
+{{else if or .Recent .Groups}}
+{{if .Recent}}<ul docs-shelf>
+ {{range .Recent}}{{template "tile" .}}{{end}}
+</ul>{{end}}
+{{if .Groups}}<div rst-list>
{{range .Groups}}
- <section docs-group>
- <h2 docs-group-label>{{.Label}}</h2>
- <ul docs-shelf>
- {{range .Rows}}{{template "tile" .}}{{end}}
- </ul>
- </section>
+ <h2 docs-group-label>{{.Label}}</h2>
+ {{range .Rows}}{{template "row" .}}{{end}}
{{end}}
-</div>
+</div>{{end}}
{{else}}
<div rst-empty>
<h2 rst-empty-title>{{.EmptyTitle}}</h2>