Slides list: the newest five as covers, everything older as rows
Docs' richer document list (design/richer-ui), for decks. GET / is a
big "Decks" title with search and a New deck pill on one line, the five
most recently edited decks as their first slides (16:9, the server's
own SVG of slide one from /d/{sqid}/slides/{id}.svg, the picture the
editor's strip shows) with title, relative time and meta under each,
and every older deck as a row in a card: a small cover, title, slide
count and last author, the rung as a status pill in words, and the date.
- A deck with no slides, or one that will not open, gets a blank sheet
in its theme's slide background ("No slides" in words). Covers are
alt="", beside the title that names them.
- Search is a GET form on ?q= (title LIKE, wildcards escaped), so it
works with scripts off and is a link; data-busy="false" keeps the
busy rule's hold off it. A result page is rows only; no match says so
with a Clear search link, which brand/decks.js swaps for the field's
own clear button.
- New deck is the bare POST from the previous commit, shown only to
someone who may create (CanCreate = member), so a removed member is
not offered a button that answers 403.
- Times are whenAgo ("Just now", "42 minutes ago", "Yesterday",
"2 Oct", "3 Dec 2025") in a <time> with the full date in its title.
Every string is a catalog key.
- Team mode's partial notice and the empty state stay; the empty state
is no longer boxed twice.
- static/decks.css: a wash of Slides' hue behind the page, a 72rem
column so five covers are not phone-sized, a swipeable shelf under
56rem (64% covers on a phone), and rows that put the pill and date
under the title on a phone. Checked at 1440 light and dark, 390 and
320 (no horizontal scroll), Chromium and WebKit, and with scripts off.
- The light: covers carry [slides-lift], rows [slides-lit], and the
page links brand/light.css and brand/pointer.js.
Tests: covers newest first with their first slide's SVG, rows with the
rung in words and a <time>, the blank cover's theme colour, search
(case, % escaped, no match), the bare create form and /decks/new, the
removed member's list with no New deck, splitRecent and whenAgo.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
9 files changed,
+953
−94
internal/slides/decks.go+238 −56internal/slides/decks_list_test.go+68 −0internal/slides/locales/en.toml+35 −11internal/slides/static/brand/decks.js+16 −0internal/slides/static/decks.css+333 −0internal/slides/team_access_test.go+4 −0internal/slides/templates/decks.html+82 −24internal/slidestest/browser_test.go+3 −3internal/slidestest/list_test.go+174 −0
diff --git a/internal/slides/decks.go b/internal/slides/decks.go| index 46d3125..9fdeba1 100644 |
| --- a/internal/slides/decks.go |
| +++ b/internal/slides/decks.go |
| @@ -27,6 +27,7 @@ import ( |
| "amadan.net/oficina/slides/internal/slides/core" |
| "amadan.net/oficina/slides/internal/slides/deck" |
| "amadan.net/oficina/slides/internal/slides/present" |
| + slidehtml "amadan.net/oficina/slides/internal/slides/render" |
| ) |
| // --- identifiers --- |
| @@ -660,22 +661,72 @@ func validRung(rung string) bool { |
| // --- GET / : the deck list --- |
| -type deckRow struct { |
| - Href string |
| - Title string |
| - Sub string |
| +// recentShelf is how many of the newest decks the list shows as covers |
| +// rather than rows: one row of them across a desktop column. Docs' |
| +// number, for Docs' reason (its handlers.go recentShelf). |
| +const recentShelf = 5 |
| + |
| +// deckCard is one deck on the list, as either a cover on the shelf or a |
| +// row under it. The same fields serve both, so a deck that ages off the |
| +// shelf says the same things in its row. |
| +type deckCard struct { |
| + Href string |
| + Title string |
| + // Sub is the meta line: how many slides, and who made the last |
| + // change (rowSub). |
| + Sub string |
| + // When is the last edit as a relative phrase (whenAgo), with the |
| + // date itself in WhenTitle and the instant in WhenISO, for the |
| + // <time> it is printed in. |
| + When string |
| + WhenTitle string |
| + WhenISO string |
| RungLabel string |
| RungTone string |
| + // Shared is true when the rung is not private: a cover names its |
| + // rung only then, as text (Docs' shared note), where a row always |
| + // carries the pill. |
| + Shared bool |
| + Cover deckCover |
| } |
| +// deckCover is a deck's first slide as the picture thumbs.go draws, or, |
| +// for a deck with no slides (or one whose document would not open), an |
| +// empty sheet in the deck's theme. |
| +type deckCover struct { |
| + // Src is the first slide's SVG, without its width hint: the template |
| + // adds the one its size wants. Empty for the blank sheet. |
| + Src string |
| + // Bg is the theme's slide background, for the blank sheet. Always a |
| + // hex colour from render's own table, never a deck author's value. |
| + Bg string |
| +} |
| + |
| +// decksPage is GET /. |
| type decksPage struct { |
| shell |
| - Title string |
| - NewHref string |
| - NewLabel string |
| - EmptyTitle string |
| - EmptyBody string |
| - Decks []deckRow |
| + Title string |
| + // CanCreate shows the New deck button. In team mode only a member |
| + // may create (teamMemberOnly), so nobody else is shown a button that |
| + // answers 403; off team mode it is always true. |
| + CanCreate bool |
| + CreateLabel string |
| + SearchLabel string |
| + SearchPlace string |
| + // Query is what was searched for, echoed back into the field so a |
| + // result page can be edited and sent again. |
| + Query string |
| + Searching bool |
| + // Recent is the newest few decks, as covers; Rows is every deck |
| + // after them, or every match when Searching. |
| + Recent []deckCard |
| + Rows []deckCard |
| + EarlierLabel string |
| + EmptyTitle string |
| + EmptyBody string |
| + NoneTitle string |
| + NoneBody string |
| + ClearLabel string |
| // Partial is team mode's "we could not check your team access": |
| // the list holds the decks granted to this person and nothing on |
| // the team rung (team_answers.go's teamPartial). Always false |
| @@ -685,48 +736,81 @@ type decksPage struct { |
| PartialBody string |
| } |
| +// maxQuery bounds the search field. A title search longer than any |
| +// title is a search for nothing; cutting it keeps the LIKE pattern |
| +// small whatever the URL carries. |
| +const maxQuery = 200 |
| + |
| +// likeEscaper escapes LIKE's two wildcards and its escape character, so |
| +// a search for "100%" finds that and not everything starting "100". |
| +var likeEscaper = strings.NewReplacer(`\`, `\\`, `%`, `\%`, `_`, `\_`) |
| + |
| // decks serves GET /: every deck this person may open, most recently |
| -// edited first. |
| +// edited first — the newest few as their first slides, the rest as |
| +// rows — or, with ?q=, the decks whose title holds those words. |
| // |
| -// The slide count costs one wasm instance per deck, because the count |
| -// lives in the document and nothing else knows it. That is the honest |
| -// price of not denormalising a number that a peer's update can change |
| -// without this process noticing; it is fine at a small team's deck |
| -// count and it is the first thing to revisit if this screen ever feels |
| -// slow — task 6's hub already holds a live handle per open deck. |
| +// Each deck is opened once, for its slide count and its first slide's |
| +// id. That costs one wasm instance per deck, because both live in the |
| +// document and nothing else knows them. That is the honest price of not |
| +// denormalising what a peer's update can change without this process |
| +// noticing; it is fine at a small team's deck count and it is the first |
| +// thing to revisit if this screen ever feels slow. |
| func (a *app) decks(w http.ResponseWriter, r *http.Request) { |
| u, ok := a.viewer(w, r) |
| if !ok { |
| return |
| } |
| + query := strings.TrimSpace(r.URL.Query().Get("q")) |
| + if len(query) > maxQuery { |
| + query = strings.ToValidUTF8(query[:maxQuery], "") |
| + } |
| + searching := query != "" |
| + |
| + scope := a.visibleDecks(r.Context(), u) |
| + if searching { |
| + scope = scope.Where(`decks.title LIKE ? ESCAPE '\'`, "%"+likeEscaper.Replace(query)+"%") |
| + } |
| var rows []Deck |
| - if err := a.visibleDecks(r.Context(), u). |
| - Order("decks.updated_at DESC, decks.id DESC").Find(&rows).Error; err != nil { |
| + if err := scope.Order("decks.updated_at DESC, decks.id DESC").Find(&rows).Error; err != nil { |
| a.fail(w, r, "list decks", err) |
| return |
| } |
| + // The app root's <title> is the app's name alone (spec §10); a |
| + // result page names what was searched for. |
| + f := frame{} |
| + if searching { |
| + f = titled(rastrillo.Tf(r, "slides.decks.search.page", "q", query)) |
| + } |
| page := decksPage{ |
| - // The app root's <title> is the app's name alone (spec §10). |
| - shell: a.shellFor(r, u, frame{}), |
| - Title: rastrillo.T(r, "slides.decks.title"), |
| - NewHref: "/decks/new", |
| - NewLabel: rastrillo.T(r, "slides.decks.new"), |
| - EmptyTitle: rastrillo.T(r, "slides.decks.empty.title"), |
| - EmptyBody: rastrillo.T(r, "slides.decks.empty.body"), |
| - Decks: make([]deckRow, 0, len(rows)), |
| + shell: a.shellFor(r, u, f), |
| + Title: rastrillo.T(r, "slides.decks.title"), |
| + CanCreate: a.member(u), |
| + CreateLabel: rastrillo.T(r, "slides.decks.new"), |
| + SearchLabel: rastrillo.T(r, "slides.decks.search.label"), |
| + SearchPlace: rastrillo.T(r, "slides.decks.search.placeholder"), |
| + Query: query, |
| + Searching: searching, |
| + EarlierLabel: rastrillo.T(r, "slides.decks.earlier"), |
| + EmptyTitle: rastrillo.T(r, "slides.decks.empty.title"), |
| + EmptyBody: rastrillo.T(r, "slides.decks.empty.body"), |
| + NoneTitle: rastrillo.T(r, "slides.decks.search.none.title"), |
| + NoneBody: rastrillo.T(r, "slides.decks.search.none.body"), |
| + ClearLabel: rastrillo.T(r, "slides.decks.search.clear"), |
| } |
| by := a.lastChangeBy(r.Context(), rows) |
| + now := time.Now() |
| + cards := make([]deckCard, 0, len(rows)) |
| for _, d := range rows { |
| - slides, counted := a.slideCount(r.Context(), d) |
| - page.Decks = append(page.Decks, deckRow{ |
| - Href: "/d/" + d.Sqid, |
| - Title: d.Title, |
| - Sub: rowSub(r, slides, counted, d.UpdatedAt, by[d.ID]), |
| - RungLabel: rungLabel(r, d.Rung), |
| - RungTone: rungTone(d.Rung), |
| - }) |
| + cards = append(cards, a.deckCardFor(r, d, by[d.ID], now)) |
| + } |
| + // A result is found by its title, so the shelf, which is about what |
| + // was worked on last, has no place on a result page. |
| + if searching { |
| + page.Rows = cards |
| + } else { |
| + page.Recent, page.Rows = splitRecent(cards, recentShelf) |
| } |
| // After listing, of the same Access the list was built with |
| // (teamPartial): a lease that lapsed while listing marks it partial. |
| @@ -738,6 +822,52 @@ func (a *app) decks(w http.ResponseWriter, r *http.Request) { |
| render(w, "decks", page) |
| } |
| +// splitRecent takes the first n cards for the shelf and leaves the rest |
| +// for the rows. Nil, not empty, for a side with nothing on it, so the |
| +// template's {{if}} reads the same either way. |
| +func splitRecent(cards []deckCard, n int) (recent, rest []deckCard) { |
| + if len(cards) == 0 { |
| + return nil, nil |
| + } |
| + if len(cards) <= n { |
| + return cards, nil |
| + } |
| + return cards[:n], cards[n:] |
| +} |
| + |
| +// deckCardFor is one deck as the list shows it. |
| +func (a *app) deckCardFor(r *http.Request, d Deck, by string, now time.Time) deckCard { |
| + slides, first, counted := a.deckGlance(r.Context(), d) |
| + card := deckCard{ |
| + Href: "/d/" + d.Sqid, |
| + Title: d.Title, |
| + Sub: rowSub(r, slides, counted, by), |
| + When: whenAgo(r, d.UpdatedAt, now), |
| + WhenTitle: d.UpdatedAt.UTC().Format("2 January 2006, 15:04 UTC"), |
| + WhenISO: d.UpdatedAt.UTC().Format(time.RFC3339), |
| + RungLabel: rungLabel(r, d.Rung), |
| + RungTone: rungTone(d.Rung), |
| + Shared: d.Rung != rungPrivate, |
| + } |
| + if first != "" { |
| + card.Cover.Src = "/d/" + d.Sqid + "/slides/" + first + ".svg" |
| + } else { |
| + card.Cover.Bg = coverBackground(d.Theme) |
| + } |
| + return card |
| +} |
| + |
| +// coverBackground is the slide background of a theme, for an empty |
| +// deck's blank cover: the deck still looks like itself before it has a |
| +// slide. A theme nothing knows is paper's, as render does with one. |
| +func coverBackground(theme string) string { |
| + vars, ok := slidehtml.ThemeVars(theme) |
| + if !ok { |
| + vars, _ = slidehtml.ThemeVars(defaultTheme) |
| + } |
| + return vars["--slides-bg"] |
| +} |
| + |
| // lastChangeBy answers, for each deck, who made its most recent write, |
| // as a person reads it: an address for a person, the robot mark plus |
| // the principal for an agent (agents.go's actorLabels). |
| @@ -793,43 +923,61 @@ func (a *app) lastChangeBy(ctx context.Context, decks []Deck) map[int64]string { |
| // slideCount opens d far enough to count its slides. A deck that will |
| // not open is logged and reported as uncounted rather than failing the |
| -// whole screen: the list is how a person reaches every OTHER deck, so |
| -// one unreadable document must not take the other nine away with it. |
| +// whole screen. |
| func (a *app) slideCount(ctx context.Context, d Deck) (int, bool) { |
| + n, _, ok := a.deckGlance(ctx, d) |
| + return n, ok |
| +} |
| + |
| +// deckGlance opens d far enough to count its slides and name the first |
| +// one, which is the deck's cover on the list. A deck that will not open |
| +// is logged and reported as uncounted rather than failing the whole |
| +// screen: the list is how a person reaches every OTHER deck, so one |
| +// unreadable document must not take the other nine away with it. |
| +func (a *app) deckGlance(ctx context.Context, d Deck) (slides int, first string, ok bool) { |
| h, view, err := a.openDeck(ctx, d) |
| if err != nil { |
| a.logger.Error("slides: open deck for the list", "deck", d.Sqid, "err", err) |
| - return 0, false |
| + return 0, "", false |
| } |
| defer h.Close(ctx) |
| - return len(view.Slides), true |
| + if len(view.Slides) > 0 { |
| + first = view.Slides[0].ID |
| + } |
| + return len(view.Slides), first, true |
| } |
| -// rowSub is a list row's meta line: how many slides, when it was last |
| -// edited, and who made that change. An uncounted deck (see slideCount) |
| -// shows the time alone rather than a count that would be a guess, and |
| -// a deck whose last actor could not be resolved shows no name rather |
| -// than a raw "person:7". |
| -func rowSub(r *http.Request, slides int, counted bool, updated time.Time, by string) string { |
| - when := whenWords(r, updated) |
| - sub := rastrillo.Tf(r, "slides.decks.row.sub.plain", "when", when) |
| +// rowSub is a deck's meta line on the list: how many slides, and who |
| +// made the last change. An uncounted deck (see deckGlance) shows no |
| +// count rather than one that would be a guess, and a deck whose last |
| +// actor could not be resolved shows no name rather than a raw |
| +// "person:7". The time is not here: the list prints it on its own, in a |
| +// <time>. |
| +func rowSub(r *http.Request, slides int, counted bool, by string) string { |
| + sub := "" |
| if counted { |
| - count := rastrillo.Tf(r, "slides.decks.row.slides", "n", slides) |
| - if slides == 1 { |
| - count = rastrillo.T(r, "slides.decks.row.slides.one") |
| + switch slides { |
| + case 0: |
| + sub = rastrillo.T(r, "slides.decks.row.slides.none") |
| + case 1: |
| + sub = rastrillo.T(r, "slides.decks.row.slides.one") |
| + default: |
| + sub = rastrillo.Tf(r, "slides.decks.row.slides", "n", slides) |
| } |
| - sub = rastrillo.Tf(r, "slides.decks.row.sub", "slides", count, "when", when) |
| } |
| - if by == "" { |
| + switch { |
| + case by == "": |
| return sub |
| + case sub == "": |
| + return rastrillo.Tf(r, "slides.decks.row.by.only", "who", by) |
| + default: |
| + return rastrillo.Tf(r, "slides.decks.row.by", "sub", sub, "who", by) |
| } |
| - return rastrillo.Tf(r, "slides.decks.row.by", "sub", sub, "who", by) |
| } |
| // whenWords is a day-grained relative phrase, falling back to the date |
| -// itself once "n days ago" stops being easier to read than a date. |
| -// Day granularity on purpose: a deck list is scanned for which deck, |
| -// not for what minute. |
| +// itself once "n days ago" stops being easier to read than a date. It |
| +// sits inside a sentence ("created today"), so it is lower case. |
| func whenWords(r *http.Request, t time.Time) string { |
| days := int(time.Since(t).Hours() / 24) |
| switch { |
| @@ -844,6 +992,40 @@ func whenWords(r *http.Request, t time.Time) string { |
| } |
| } |
| +// whenAgo is the deck list's own relative time, standing alone under a |
| +// cover or at the end of a row: finer than whenWords on the day itself, |
| +// because the newest decks on the shelf are usually all from today and |
| +// "today" five times over tells them apart by nothing. Past a week it |
| +// is the date, short, with the year only when it is not this one. The |
| +// full date is in the <time>'s title beside it. |
| +func whenAgo(r *http.Request, t, now time.Time) string { |
| + d := now.Sub(t) |
| + switch { |
| + case d < time.Minute: |
| + return rastrillo.T(r, "slides.when.now") |
| + case d < time.Hour: |
| + n := int(d / time.Minute) |
| + if n == 1 { |
| + return rastrillo.T(r, "slides.when.minutes.one") |
| + } |
| + return rastrillo.Tf(r, "slides.when.minutes", "n", n) |
| + case d < 24*time.Hour: |
| + n := int(d / time.Hour) |
| + if n == 1 { |
| + return rastrillo.T(r, "slides.when.hours.one") |
| + } |
| + return rastrillo.Tf(r, "slides.when.hours", "n", n) |
| + case d < 48*time.Hour: |
| + return rastrillo.T(r, "slides.when.yesterday.alone") |
| + case d < 7*24*time.Hour: |
| + return rastrillo.Tf(r, "slides.when.days", "n", int(d/(24*time.Hour))) |
| + case t.Year() == now.Year(): |
| + return t.Format("2 Jan") |
| + default: |
| + return t.Format("2 Jan 2006") |
| + } |
| +} |
| + |
| // --- GET /decks/new, POST /decks --- |
| // A new deck is made at once and opened in the editor, with no title box |
diff --git a/internal/slides/decks_list_test.go b/internal/slides/decks_list_test.go| new file mode 100644 |
| index 0000000..4698a8d |
| --- /dev/null |
| +++ b/internal/slides/decks_list_test.go |
| @@ -0,0 +1,68 @@ |
| +package slides |
| + |
| +import ( |
| + "net/http/httptest" |
| + "reflect" |
| + "testing" |
| + "time" |
| +) |
| + |
| +// The shelf takes the newest cards, in order; the rows get the rest. |
| +func TestSplitRecent(t *testing.T) { |
| + cards := func(titles ...string) []deckCard { |
| + var out []deckCard |
| + for _, s := range titles { |
| + out = append(out, deckCard{Title: s}) |
| + } |
| + return out |
| + } |
| + titles := func(cs []deckCard) []string { |
| + var out []string |
| + for _, c := range cs { |
| + out = append(out, c.Title) |
| + } |
| + return out |
| + } |
| + recent, rest := splitRecent(cards("a", "b", "c", "d", "e", "f", "g"), 5) |
| + if !reflect.DeepEqual(titles(recent), []string{"a", "b", "c", "d", "e"}) || !reflect.DeepEqual(titles(rest), []string{"f", "g"}) { |
| + t.Errorf("shelf %v, rows %v", titles(recent), titles(rest)) |
| + } |
| + if recent, rest = splitRecent(cards("a", "b"), 5); len(recent) != 2 || rest != nil { |
| + t.Errorf("fewer decks than the shelf holds: shelf %v, rows %v", titles(recent), rest) |
| + } |
| + if recent, rest = splitRecent(nil, 5); recent != nil || rest != nil { |
| + t.Errorf("no decks: shelf %v, rows %v", recent, rest) |
| + } |
| +} |
| + |
| +// The list's own times: finer than a day on the day itself, then days, |
| +// then the date, with the year only when it is not this one. A bare |
| +// request carries no catalog, so the phrases come back as their keys, |
| +// which is what picks the branch; the date is data, not copy. |
| +func TestWhenAgo(t *testing.T) { |
| + r := httptest.NewRequest("GET", "/", nil) |
| + now := time.Date(2026, 11, 11, 12, 0, 0, 0, time.UTC) |
| + for _, c := range []struct { |
| + ago time.Duration |
| + at time.Time |
| + want string |
| + }{ |
| + {ago: 10 * time.Second, want: "slides.when.now"}, |
| + {ago: 90 * time.Second, want: "slides.when.minutes.one"}, |
| + {ago: 42 * time.Minute, want: "slides.when.minutes"}, |
| + {ago: 61 * time.Minute, want: "slides.when.hours.one"}, |
| + {ago: 23 * time.Hour, want: "slides.when.hours"}, |
| + {ago: 30 * time.Hour, want: "slides.when.yesterday.alone"}, |
| + {ago: 3 * 24 * time.Hour, want: "slides.when.days"}, |
| + {at: time.Date(2026, 10, 2, 9, 0, 0, 0, time.UTC), want: "2 Oct"}, |
| + {at: time.Date(2025, 12, 3, 9, 0, 0, 0, time.UTC), want: "3 Dec 2025"}, |
| + } { |
| + at := c.at |
| + if at.IsZero() { |
| + at = now.Add(-c.ago) |
| + } |
| + if got := whenAgo(r, at, now); got != c.want { |
| + t.Errorf("whenAgo(%v before) = %q, want %q", now.Sub(at), got, c.want) |
| + } |
| + } |
| +} |
diff --git a/internal/slides/locales/en.toml b/internal/slides/locales/en.toml| index 26431d2..e19776f 100644 |
| --- a/internal/slides/locales/en.toml |
| +++ b/internal/slides/locales/en.toml |
| @@ -95,29 +95,53 @@ slides.decks.new = "New deck" |
| # deck starts as "Untitled deck" and is named in the editor. |
| slides.decks.new.body = "Start a blank deck and it opens in the editor, where you can name it and choose its look." |
| slides.decks.new.submit = "Create deck" |
| - |
| -# A list row's meta line: how many slides, and when it last changed. |
| -# Two keys for the count because English has two forms and the catalog |
| -# has no plural machinery — the handler picks (decks.go's rowSub). |
| +# The list's search: a GET form on the title (decks.go's decks). label |
| +# is the field's and the magnifier's accessible name, placeholder the |
| +# hint inside the field. page is the result page's <title> part. |
| +slides.decks.search.label = "Search decks" |
| +slides.decks.search.placeholder = "Search by title" |
| +slides.decks.search.page = "Search: {q}" |
| +slides.decks.search.none.title = "No decks match" |
| +slides.decks.search.none.body = "Nothing here has that in its title. Check the spelling, or try a shorter word." |
| +slides.decks.search.clear = "Clear search" |
| +# The heading over the rows: every deck older than the five shown as |
| +# covers at the top of the list. |
| +slides.decks.earlier = "Earlier" |
| + |
| +# A deck's meta line on the list: how many slides, and who made the |
| +# last change (the time is printed beside it, on its own). Three keys |
| +# for the count because English has two forms and an empty deck reads |
| +# better in words, and the catalog has no plural machinery — the |
| +# handler picks (decks.go's rowSub). |
| +slides.decks.row.slides.none = "No slides" |
| slides.decks.row.slides.one = "1 slide" |
| slides.decks.row.slides = "{n} slides" |
| -slides.decks.row.sub = "{slides} · edited {when}" |
| -# The same line for a deck whose document would not open: the time is |
| -# still true, and a slide count would be a guess. |
| -slides.decks.row.sub.plain = "edited {when}" |
| # Who made that last change (spec §6.2's actor). A person is their |
| # address; an agent is the robot mark and its principal, so a deck a |
| # program has been editing says so on the row rather than only in a |
| # history nobody opens. |
| slides.decks.row.by = "{sub} · by {who}" |
| +# The same, for a deck whose document would not open: a slide count |
| +# would be a guess. |
| +slides.decks.row.by.only = "By {who}" |
| -# slides.when.* — day-grained relative time. A deck list is scanned for |
| -# which deck, never for what minute, so nothing here is finer than a |
| -# day, and past a week the date itself is easier to read than a count. |
| +# slides.when.* — day-grained relative time, inside a sentence ("created |
| +# today"), and past a week the date itself is easier to read than a |
| +# count. |
| slides.when.today = "today" |
| slides.when.yesterday = "yesterday" |
| slides.when.days = "{n} days ago" |
| slides.when.on = "on {date}" |
| +# The deck list's own times, standing alone under a cover or at the end |
| +# of a row (decks.go's whenAgo), so capitalised, and finer than a day: |
| +# the newest decks are usually all from today. Past a week the list |
| +# shows the date itself. |
| +slides.when.now = "Just now" |
| +slides.when.minutes.one = "1 minute ago" |
| +slides.when.minutes = "{n} minutes ago" |
| +slides.when.hours.one = "1 hour ago" |
| +slides.when.hours = "{n} hours ago" |
| +slides.when.yesterday.alone = "Yesterday" |
| # slides.deck.* — one deck: its own page, its settings, its deletion. |
| # |
diff --git a/internal/slides/static/brand/decks.js b/internal/slides/static/brand/decks.js| new file mode 100644 |
| index 0000000..4ab6151 |
| --- /dev/null |
| +++ b/internal/slides/static/brand/decks.js |
| @@ -0,0 +1,16 @@ |
| +/* brand/decks.js — the deck list's search field (Docs' brand/list.js). On a |
| + result page the field's own clear button (the × a search input draws) |
| + clears the search, not just the field: emptying it goes back to every |
| + deck, and the "Clear search" link under the results, which is the |
| + same way out for a reader with no script, is taken away as |
| + redundant. */ |
| +(function () { |
| + "use strict"; |
| + var input = document.querySelector("[slides-search-input]"); |
| + if (!input || !input.value) return; |
| + var clear = document.querySelector("[slides-search-clear]"); |
| + if (clear) clear.hidden = true; |
| + input.addEventListener("input", function () { |
| + if (input.value === "") location.assign("/"); |
| + }); |
| +})(); |
diff --git a/internal/slides/static/decks.css b/internal/slides/static/decks.css| new file mode 100644 |
| index 0000000..dc49cee |
| --- /dev/null |
| +++ b/internal/slides/static/decks.css |
| @@ -0,0 +1,333 @@ |
| +/* decks.css — GET /, the deck list (templates/decks.html). Docs' list |
| + (its design/richer-ui list.html), for decks: the newest five as their |
| + first slides lying on a desk, everything older as rows. The light on |
| + them is brand/light.css's; this file is the still design. */ |
| + |
| +/* The desk. The page under the decks is lit from above by a wash of |
| + Slides' own hue (the icon's glow, estilo theme/apps.go hue 56, at the |
| + aurora's lightness). One hue only, as the app icons have; the suite's |
| + full aurora stays on Home. Painted on the body so it reaches the bar |
| + and the edges without anything here overflowing. */ |
| +body:has([slides-decks]) { |
| + background: |
| + radial-gradient(ellipse 70rem 28rem at 50% -6rem, |
| + light-dark(oklch(0.88 0.06 56 / 0.5), oklch(0.42 0.08 56 / 0.14)), |
| + transparent 70%) |
| + no-repeat, |
| + var(--rst-bg); |
| +} |
| +[slides-decks] { |
| + padding-block: var(--rst-sp-4) var(--rst-sp-6); |
| +} |
| +/* A wider column than a form's: five slides across at 64rem were each |
| + narrower than a phone's cover. Still well inside a laptop's width. */ |
| +[rst-page]:has(> [slides-decks]) { |
| + max-width: 72rem; |
| +} |
| + |
| +/* The header: the screen's name, large and set tight, with search and |
| + New deck on the same line. On a phone the title and New deck share the |
| + first line and search takes the whole second one. */ |
| +[slides-decks-head] { |
| + display: flex; |
| + flex-wrap: wrap; |
| + align-items: center; |
| + justify-content: space-between; |
| + gap: var(--rst-sp-3) var(--rst-sp-5); |
| + margin-block-end: var(--rst-sp-5); |
| +} |
| +[slides-decks-head] h1 { |
| + margin: 0; |
| + font-size: clamp(1.75rem, 1.3rem + 1.6vw, 2.5rem); |
| + font-weight: 700; |
| + letter-spacing: -0.025em; |
| + line-height: 1.1; |
| +} |
| +/* Search and create as one group. They stay two separate forms, never |
| + one: unrelated actions with different methods and targets. */ |
| +[slides-decks-actions] { |
| + display: flex; |
| + flex: 1 1 22rem; |
| + justify-content: flex-end; |
| + align-items: center; |
| + gap: var(--rst-sp-3); |
| + min-inline-size: 0; |
| +} |
| +/* Search is one field with its submit inside it, at the start, as the |
| + magnifier, which keeps "Search decks" as its name. The field takes |
| + whatever the row leaves it, down to nothing: min-inline-size: 0 lifts |
| + a flex item's automatic minimum, which for an <input> is its content |
| + and would otherwise push the page sideways at 320px (SC 1.4.10). */ |
| +[slides-search] { |
| + position: relative; |
| + display: flex; |
| + flex: 0 1 20rem; |
| + min-inline-size: 0; |
| +} |
| +[slides-search] [rst-input] { |
| + flex: 1 1 auto; |
| + min-inline-size: 0; |
| + min-block-size: 40px; |
| + padding-inline-start: 40px; |
| + border-color: transparent; |
| + border-radius: var(--rst-radius-pill); |
| + background: light-dark(rgb(255 255 255 / 0.8), rgb(255 255 255 / 0.06)); |
| + box-shadow: inset 0 0 0 1px var(--rst-line-strong), 0 1px 2px light-dark(rgb(20 30 60 / 0.06), transparent); |
| +} |
| +[slides-search] [rst-input]:hover { |
| + box-shadow: inset 0 0 0 1px var(--rst-text-muted); |
| +} |
| +[slides-search] [rst-input]:focus-visible { |
| + outline: 2px solid var(--rst-accent); |
| + outline-offset: 1px; |
| +} |
| +[slides-search-submit] { |
| + position: absolute; |
| + inset-block: 0; |
| + inset-inline-start: 2px; |
| + display: grid; |
| + place-items: center; |
| + inline-size: 38px; |
| + padding: 0; |
| + border: 0; |
| + border-radius: var(--rst-radius-pill); |
| + background: transparent; |
| + color: var(--rst-text-muted); |
| + cursor: pointer; |
| +} |
| +[slides-search-submit]:hover { |
| + color: var(--rst-accent); |
| +} |
| +[slides-search-submit]:focus-visible { |
| + outline: 2px solid var(--rst-accent); |
| + outline-offset: -2px; |
| +} |
| +[slides-search-submit] svg, |
| +[slides-create] svg { |
| + inline-size: 18px; |
| + block-size: 18px; |
| +} |
| +[slides-create] { |
| + flex: none; |
| +} |
| +[slides-create] button { |
| + min-block-size: 40px; |
| + padding-inline: var(--rst-sp-4) var(--rst-sp-5); |
| + border-radius: var(--rst-radius-pill); |
| + font-size: var(--rst-fs-base, 1rem); |
| + 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); |
| +} |
| +@media (max-width: 36rem) { |
| + [slides-decks-actions] { |
| + display: contents; |
| + } |
| + [slides-decks-head] h1 { |
| + flex: 1 1 auto; |
| + } |
| + [slides-search] { |
| + order: 3; |
| + flex: 1 1 100%; |
| + } |
| +} |
| + |
| +/* A cover: a deck's first slide, the server's own picture of it |
| + (thumbs.go), at 16:9 like every slide. A deck with no slides is the |
| + same sheet in its theme's background, set inline. The slide is its |
| + own colours in either scheme, as a projected slide is. */ |
| +[slides-cover] { |
| + display: block; |
| + flex: none; |
| + aspect-ratio: 16 / 9; |
| + border-radius: 4px; |
| + background-color: #faf7f0; |
| + overflow: hidden; |
| + box-shadow: |
| + 0 0 0 1px light-dark(rgb(23 32 60 / 0.10), rgb(255 255 255 / 0.10)), |
| + 0 1px 2px rgb(23 32 60 / 0.08); |
| +} |
| +[slides-cover] > img { |
| + display: block; |
| + inline-size: 100%; |
| + block-size: 100%; |
| + object-fit: cover; |
| +} |
| + |
| +/* The shelf: the newest decks as their first slides, one row of them |
| + across the column. Narrower, it is a row you swipe, a cover and a half |
| + or more wide, so the rows below are still on the first screen. */ |
| +[slides-shelf] { |
| + display: grid; |
| + grid-template-columns: repeat(5, minmax(0, 1fr)); |
| + gap: var(--rst-sp-5) var(--rst-sp-4); |
| + margin: 0 0 var(--rst-sp-6); |
| + padding: 0; |
| + list-style: none; |
| +} |
| +@media (max-width: 56rem) { |
| + [slides-shelf] { |
| + grid-template-columns: none; |
| + grid-auto-flow: column; |
| + grid-auto-columns: 34%; |
| + gap: var(--rst-sp-4); |
| + overflow-x: auto; |
| + overscroll-behavior-x: contain; |
| + scroll-snap-type: x mandatory; |
| + scrollbar-width: none; |
| + /* Room for the covers' 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); |
| + } |
| + [slides-shelf] > li { |
| + scroll-snap-align: start; |
| + } |
| +} |
| +@media (max-width: 36rem) { |
| + [slides-shelf] { |
| + grid-auto-columns: 64%; |
| + } |
| +} |
| +[slides-tile] { |
| + display: flex; |
| + flex-direction: column; |
| + gap: 2px; |
| + min-inline-size: 0; |
| + color: var(--rst-text); |
| + text-decoration: none; |
| + border-radius: var(--rst-radius-sm); |
| +} |
| +[slides-tile]:focus-visible { |
| + outline: 2px solid var(--rst-accent); |
| + outline-offset: 6px; |
| +} |
| +[slides-tile] [slides-cover] { |
| + inline-size: 100%; |
| + margin-block-end: var(--rst-sp-3); |
| + border-radius: 6px; |
| + box-shadow: |
| + 0 0 0 1px light-dark(rgb(23 32 60 / 0.08), rgb(255 255 255 / 0.08)), |
| + 0 1px 2px rgb(23 32 60 / 0.08), |
| + 0 10px 24px -12px light-dark(rgb(23 32 60 / 0.30), rgb(0 0 0 / 0.7)); |
| +} |
| +[slides-tile-title] { |
| + font-size: var(--rst-fs-sm, 0.875rem); |
| + font-weight: 600; |
| + line-height: 1.3; |
| + overflow-wrap: anywhere; |
| + display: -webkit-box; |
| + -webkit-box-orient: vertical; |
| + -webkit-line-clamp: 2; |
| + line-clamp: 2; |
| + overflow: hidden; |
| +} |
| +[slides-tile]:hover [slides-tile-title] { |
| + color: var(--rst-accent); |
| +} |
| +[slides-tile-meta], |
| +[slides-tile-sub] { |
| + color: var(--rst-text-muted); |
| + font-size: var(--rst-fs-xs, 0.75rem); |
| + line-height: 1.4; |
| +} |
| +[slides-tile-meta] { |
| + display: flex; |
| + flex-wrap: wrap; |
| + gap: 0 var(--rst-sp-2); |
| +} |
| +/* The rung, on a cover, only when it is not private: a word, as Docs' |
| + shared note, never a colour alone. */ |
| +[slides-tile-rung]::before { |
| + content: "·"; |
| + content: "·" / ""; |
| + margin-inline-end: var(--rst-sp-2); |
| +} |
| +[slides-tile-sub] { |
| + overflow: hidden; |
| + white-space: nowrap; |
| + text-overflow: ellipsis; |
| +} |
| + |
| +/* The rows: everything older than the shelf, and every search result. |
| + rastrillo's list and row, which already stretch the title link over |
| + the whole row and tint it on hover; a small cover at the start of |
| + each. */ |
| +[slides-decks] [rst-list] { |
| + box-shadow: 0 1px 2px light-dark(rgb(23 32 60 / 0.05), transparent); |
| +} |
| +[slides-decks] [rst-row] { |
| + gap: var(--rst-sp-4); |
| +} |
| +[rst-row] [slides-cover] { |
| + inline-size: 72px; |
| + margin-block: 2px; |
| + box-shadow: |
| + 0 0 0 1px light-dark(rgb(23 32 60 / 0.10), rgb(255 255 255 / 0.10)), |
| + 0 1px 2px rgb(23 32 60 / 0.08), |
| + 0 4px 10px -6px rgb(23 32 60 / 0.25); |
| +} |
| +[slides-decks] [rst-row-main] > a { |
| + font-weight: 600; |
| +} |
| +[slides-decks] [rst-row-sub] { |
| + overflow: hidden; |
| + white-space: nowrap; |
| + text-overflow: ellipsis; |
| +} |
| +[slides-row-trail] { |
| + display: flex; |
| + flex: none; |
| + align-items: center; |
| + gap: var(--rst-sp-4); |
| +} |
| +[slides-row-when] { |
| + flex: none; |
| + min-inline-size: 6.5rem; |
| + color: var(--rst-text-muted); |
| + font-size: var(--rst-fs-sm); |
| + font-variant-numeric: tabular-nums; |
| + text-align: end; |
| +} |
| +/* A phone: the cover, then the title and its line, then the rung and |
| + the date under them, so nothing is squeezed to a sliver at 320px. */ |
| +@media (max-width: 36rem) { |
| + [slides-decks] [rst-row] { |
| + display: grid; |
| + grid-template-columns: auto minmax(0, 1fr); |
| + align-items: center; |
| + gap: var(--rst-sp-1) var(--rst-sp-3); |
| + } |
| + [slides-decks] [rst-row] [slides-cover] { |
| + grid-row: span 2; |
| + inline-size: 88px; |
| + } |
| + [slides-row-trail] { |
| + flex-wrap: wrap; |
| + gap: var(--rst-sp-1) var(--rst-sp-3); |
| + min-inline-size: 0; |
| + } |
| + [slides-row-when] { |
| + min-inline-size: 0; |
| + text-align: start; |
| + font-size: var(--rst-fs-xs); |
| + } |
| +} |
| +/* A heading inside the card: sentence case, the muted ink, weight doing |
| + the work rather than capitals. */ |
| +[slides-rows-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); |
| +} |
| +/* The way back out of a result page, under the results: it is about the |
| + list being shown, not about the controls that produced it. */ |
| +[slides-search-clear] { |
| + margin-block-start: var(--rst-sp-6); |
| + font-size: var(--rst-fs-sm); |
| +} |
| +[slides-decks] [rst-empty] { |
| + margin-block-start: var(--rst-sp-6); |
| +} |
diff --git a/internal/slides/team_access_test.go b/internal/slides/team_access_test.go| index b9a9b76..19d5d01 100644 |
| --- a/internal/slides/team_access_test.go |
| +++ b/internal/slides/team_access_test.go |
| @@ -146,6 +146,10 @@ func TestTeamRemovalRevokesAHomeOnlyMembersExistingSession(t *testing.T) { |
| if list.Code != 200 || strings.Contains(list.Body.String(), "data-partial") || strings.Contains(list.Body.String(), "Team plan") { |
| t.Fatalf("removed member's list = %d (partial or team deck shown)", list.Code) |
| } |
| + // Nor is a button offered that would only answer 403. |
| + if strings.Contains(list.Body.String(), "slides-create") { |
| + t.Fatal("removed member's list offers New deck") |
| + } |
| if got := f.get("/decks/new"); got.Code != http.StatusForbidden { |
| t.Fatalf("removed member's new deck page = %d, want 403", got.Code) |
| } |
diff --git a/internal/slides/templates/decks.html b/internal/slides/templates/decks.html| index dddbf1f..87de174 100644 |
| --- a/internal/slides/templates/decks.html |
| +++ b/internal/slides/templates/decks.html |
| @@ -1,37 +1,95 @@ |
| -{{/* decks — GET /, the deck list. |
| +{{/* decks — GET /, the deck list: Docs' document list (its |
| + design/richer-ui list.html), for decks. |
| - One job: show the decks, and carry the single link that starts a |
| - new one. The create form is a page of its own (SKILL.md §7) — an |
| - empty list is step one of that flow, not an exception to it, so the |
| - empty state carries the same call to action the header does rather |
| - than a form inlined here. |
| + The header is the screen's name, large, with search and New deck on |
| + one line. They are two separate forms, never one: unrelated |
| + actions with different methods and targets (GET / and POST |
| + /decks). New deck is one button and no title box: the deck is made |
| + "Untitled deck" and opens in the editor, where a person names it |
| + once they know what it is (decks.go's createDeck). It is shown only |
| + to someone who may create (CanCreate), so nobody is offered a |
| + button that answers 403. |
| - The rows live in [rst-list], which holds rows and nothing else. The |
| - rung rides as a status-pill inside each row: always visible text, |
| - never colour alone. */}} |
| + Search is a GET form, so a search is a link — bookmarkable, |
| + reloadable, reachable with Back — and the whole feature works with |
| + no script. data-busy="false": a search shows something rather than |
| + changing anything, so the busy rule's hold (busy.js) would only |
| + delay the results. |
| + |
| + Then the newest five decks as their first slides ([slides-shelf]), |
| + each one link — cover, title and meta — and everything older as |
| + rows in [rst-list], each with a small cover, its meta line, its |
| + rung as a status-pill (always visible text, never colour alone) and |
| + the date. A result page is rows only: a result is found by its |
| + title, and the shelf is about what was worked on last. |
| + |
| + A cover is the server's own picture of the slide (thumbs.go), the |
| + same one the editor's strip shows, in an <img alt="">: it is |
| + decorative, wholly redundant with the title beside it, and its |
| + words are not the deck's name. A deck with no slides gets a blank |
| + sheet in its theme's background. |
| + |
| + The light (brand/light.css, brand/pointer.js) is opted into with |
| + [slides-lift] on the covers and [slides-lit] on the rows; with no |
| + script or under reduced motion the page is the still design. */}} |
| +{{define "page-head"}}<link rel="stylesheet" href="{{asset "static/brand/light.css"}}"> |
| +<link rel="stylesheet" href="{{asset "static/decks.css"}}"> |
| +<script defer src="{{asset "static/brand/pointer.js"}}"></script> |
| +<script defer src="{{asset "static/brand/decks.js"}}"></script>{{end}} |
| +{{define "deck-tile"}}<li><a slides-tile slides-lift href="{{.Href}}"> |
| + <span slides-cover slides-lift-face aria-hidden="true"{{if .Cover.Bg}} style="background-color: {{.Cover.Bg}}"{{end}}>{{with .Cover.Src}}<img src="{{.}}?w=480" alt="" decoding="async" width="320" height="180">{{end}}</span> |
| + <span slides-tile-title>{{.Title}}</span> |
| + <span slides-tile-meta><time datetime="{{.WhenISO}}" title="{{.WhenTitle}}">{{.When}}</time>{{if .Shared}}<span slides-tile-rung>{{.RungLabel}}</span>{{end}}</span> |
| + {{with .Sub}}<span slides-tile-sub>{{.}}</span>{{end}} |
| + </a></li>{{end}} |
| +{{define "deck-row"}}<div rst-row slides-lit> |
| + <span slides-cover aria-hidden="true"{{if .Cover.Bg}} style="background-color: {{.Cover.Bg}}"{{end}}>{{with .Cover.Src}}<img src="{{.}}?w=160" alt="" loading="lazy" decoding="async" width="64" height="36">{{end}}</span> |
| + <span rst-row-main><a href="{{.Href}}">{{.Title}}</a>{{with .Sub}}<small rst-row-sub>{{.}}</small>{{end}}</span> |
| + <span slides-row-trail>{{template "status-pill" dict "Tone" .RungTone "Label" .RungLabel}}<time slides-row-when datetime="{{.WhenISO}}" title="{{.WhenTitle}}">{{.When}}</time></span> |
| + </div>{{end}} |
| {{define "content"}} |
| -{{template "page-header" dict |
| - "Title" .Title |
| - "ActionHref" .NewHref "ActionLabel" .NewLabel "ActionIcon" "plus"}} |
| +<div slides-decks> |
| +<header slides-decks-head> |
| + <h1>{{.Title}}</h1> |
| + <div slides-decks-actions> |
| + <form slides-search method="get" action="/" role="search" data-busy="false"> |
| + <input rst-input slides-search-input type="search" name="q" value="{{.Query}}" |
| + placeholder="{{.SearchPlace}}" aria-label="{{.SearchLabel}}" autocomplete="off" maxlength="200"> |
| + <button slides-search-submit type="submit" title="{{.SearchLabel}}" aria-label="{{.SearchLabel}}">{{icon "search"}}</button> |
| + </form> |
| +{{- if .CanCreate}} |
| + <form slides-create method="post" action="/decks"> |
| + <button rst-btn="primary" type="submit">{{icon "plus"}}<span>{{.CreateLabel}}</span></button> |
| + </form> |
| +{{- end}} |
| + </div> |
| +</header> |
| {{if .Partial}}{{/* Team mode, standing Unknown (Paul, 2026-10-28): the |
| list is what this person reaches without the team — the decks |
| granted to them — and says so, rather than the whole page |
| answering 503. Rendered only then, and nothing at all otherwise. */}}<div data-partial> |
| {{template "callout" dict "Tone" "warning" "Title" .PartialTitle "Body" .PartialBody}} |
| </div> |
| -{{end}}{{if .Decks}} |
| +{{end}} |
| +{{- if .Searching}} |
| +{{if .Rows}} |
| <div rst-list> |
| - {{range .Decks}} |
| - {{template "list-row-action" dict |
| - "Href" .Href "Main" .Title "Sub" .Sub |
| - "StatusLabel" .RungLabel "StatusTone" .RungTone}} |
| - {{end}} |
| -</div> |
| -{{else if not .Partial}} |
| -<div rst-box> |
| - {{template "empty-state" dict |
| - "Title" .EmptyTitle "Body" .EmptyBody |
| - "ActionHref" .NewHref "ActionLabel" .NewLabel}} |
| + {{range .Rows}}{{template "deck-row" .}}{{end}} |
| </div> |
| +{{else}} |
| +{{template "empty-state" dict "Title" .NoneTitle "Body" .NoneBody}} |
| +{{end}} |
| +<p slides-search-clear><a href="/">{{.ClearLabel}}</a></p> |
| +{{- else if or .Recent .Rows}} |
| +{{if .Recent}}<ul slides-shelf> |
| + {{range .Recent}}{{template "deck-tile" .}}{{end}} |
| +</ul>{{end}} |
| +{{if .Rows}}<div rst-list> |
| + <h2 slides-rows-label>{{.EarlierLabel}}</h2> |
| + {{range .Rows}}{{template "deck-row" .}}{{end}} |
| +</div>{{end}} |
| +{{- else if not .Partial}} |
| +{{template "empty-state" dict "Title" .EmptyTitle "Body" .EmptyBody}} |
| {{end}} |
| +</div> |
| {{end}} |
diff --git a/internal/slidestest/browser_test.go b/internal/slidestest/browser_test.go| index 944b36c..1c57d38 100644 |
| --- a/internal/slidestest/browser_test.go |
| +++ b/internal/slidestest/browser_test.go |
| @@ -719,9 +719,9 @@ func TestBrowserDeleteToEmptyThenNewSlide(t *testing.T) { |
| rig, mailer := newRig(t) |
| browserSignIn(t, rig, mailer) |
| rig.Run( |
| - chromedp.Navigate(rig.Origin+"/decks/new"), |
| - chromedp.WaitVisible(`form[action="/decks"] button[type="submit"]`, chromedp.ByQuery), |
| - chromedp.Click(`form[action="/decks"] button[type="submit"]`, chromedp.ByQuery), |
| + chromedp.Navigate(rig.Origin+"/"), |
| + chromedp.WaitVisible(`[slides-create] button`, chromedp.ByQuery), |
| + chromedp.Click(`[slides-create] button`, chromedp.ByQuery), |
| waitFor(`/^\/d\/[^/]+\/edit$/.test(location.pathname)`), |
| ) |
| var deck string |
diff --git a/internal/slidestest/list_test.go b/internal/slidestest/list_test.go| new file mode 100644 |
| index 0000000..f54a754 |
| --- /dev/null |
| +++ b/internal/slidestest/list_test.go |
| @@ -0,0 +1,174 @@ |
| +package slidestest |
| + |
| +import ( |
| + "net/http" |
| + "net/url" |
| + "regexp" |
| + "strings" |
| + "testing" |
| +) |
| + |
| +// shelfTile is one cover on the shelf: the tile's link and the picture |
| +// inside it. |
| +var shelfTile = regexp.MustCompile(`<a slides-tile slides-lift href="(/d/[a-z0-9]{10})">\s*<span slides-cover[^>]*>(?:<img src="([^"]+)")?`) |
| + |
| +// rowLink is one row's title link. |
| +var rowLink = regexp.MustCompile(`<span rst-row-main><a href="(/d/[a-z0-9]{10})">([^<]*)</a>`) |
| + |
| +// TestListShowsTheNewestFiveAsCoversAndTheRestAsRows: the newest five |
| +// decks are their first slides, newest first; everything older is a row |
| +// with a small cover and its rung in words. |
| +func TestListShowsTheNewestFiveAsCoversAndTheRestAsRows(t *testing.T) { |
| + a := newApp(t) |
| + cookies := signedIn(t, a, allowedAddress) |
| + // The sample deck is first and so oldest; six more after it. |
| + var made []string |
| + for _, title := range []string{"One", "Two", "Three", "Four", "Five", "Six"} { |
| + made = append(made, createDeck(t, a, cookies, title)) |
| + } |
| + |
| + page := mustGet(t, a, "/", http.StatusOK, cookies).Body.String() |
| + tiles := shelfTile.FindAllStringSubmatch(page, -1) |
| + if len(tiles) != 5 { |
| + t.Fatalf("the shelf holds %d covers, want 5:\n%s", len(tiles), page) |
| + } |
| + for i, tile := range tiles { |
| + if want := made[len(made)-1-i]; tile[1] != want { |
| + t.Errorf("cover %d links %s, want %s (newest first)", i, tile[1], want) |
| + } |
| + // The deck's first slide, as the picture thumbs.go serves. |
| + if !strings.HasPrefix(tile[2], tile[1]+"/slides/") || !strings.Contains(tile[2], ".svg?w=") { |
| + t.Errorf("cover %d is %q, want its first slide's SVG", i, tile[2]) |
| + } |
| + pic := mustGet(t, a, strings.SplitN(tile[2], "?", 2)[0], http.StatusOK, cookies) |
| + if ct := pic.Header().Get("Content-Type"); !strings.HasPrefix(ct, "image/svg+xml") { |
| + t.Errorf("cover %d answers %q, want an SVG", i, ct) |
| + } |
| + } |
| + |
| + rows := rowLink.FindAllStringSubmatch(page, -1) |
| + if len(rows) != 2 || rows[0][1] != made[0] || rows[1][2] != sampleDeckTitle { |
| + t.Fatalf("rows = %v, want One then the sample deck", rows) |
| + } |
| + // The rung is words in every row, never colour alone. |
| + if n := strings.Count(page, `rst-status rst-tone="neutral">Only me<`); n != 2 { |
| + t.Errorf("%d rows say Only me, want 2", n) |
| + } |
| + // A time is relative, with the date itself in its title. |
| + if !regexp.MustCompile(`<time slides-row-when datetime="[^"]+" title="[^"]+">Just now</time>`).MatchString(page) { |
| + t.Errorf("a row's time is not a <time> with its date in the title:\n%s", page) |
| + } |
| + if !strings.Contains(page, `<h2 slides-rows-label>Earlier</h2>`) { |
| + t.Errorf("the rows have no heading") |
| + } |
| + // Covers are decorative, beside the title that names the deck. |
| + if covers, empty := len(regexp.MustCompile(`<img src="/d/`).FindAllString(page, -1)), len(regexp.MustCompile(`<img src="/d/[^>]* alt=""`).FindAllString(page, -1)); covers != 7 || empty != covers { |
| + t.Errorf("%d covers, %d with alt=\"\": want 7, all empty (the title beside each names the deck)", covers, empty) |
| + } |
| +} |
| + |
| +// TestAnEmptyDeckGetsABlankCoverInItsTheme: no slide, no picture to |
| +// fetch, and the sheet is the theme's own slide background. |
| +func TestAnEmptyDeckGetsABlankCoverInItsTheme(t *testing.T) { |
| + a := newApp(t) |
| + cookies := signedIn(t, a, allowedAddress) |
| + token := mintAgent(t, a, cookies, "claude") |
| + out := apiJSON(t, a, http.MethodPost, "/api/v1/decks", token, `{"title":"Nothing yet","theme":"forest"}`, http.StatusCreated) |
| + sqid := out["sqid"].(string) |
| + got := apiJSON(t, a, http.MethodGet, "/api/v1/decks/"+sqid, token, "", http.StatusOK) |
| + slide := got["slides"].([]any)[0].(map[string]any)["id"].(string) |
| + apiJSON(t, a, http.MethodPost, "/api/v1/decks/"+sqid+"/ops", token, |
| + `{"ops":[{"op":"remove_slide","id":`+quote(slide)+`}]}`, http.StatusOK) |
| + |
| + page := mustGet(t, a, "/", http.StatusOK, cookies).Body.String() |
| + m := regexp.MustCompile(`<a slides-tile slides-lift href="/d/` + sqid + `">\s*<span slides-cover[^>]*>(<img)?`).FindStringSubmatch(page) |
| + if m == nil { |
| + t.Fatalf("the empty deck is not on the shelf:\n%s", page) |
| + } |
| + if m[1] != "" { |
| + t.Errorf("the empty deck's cover has a picture") |
| + } |
| + if !strings.Contains(m[0], `style="background-color: #0f2418"`) { |
| + t.Errorf("the empty deck's cover is %q, want forest's background", m[0]) |
| + } |
| + if !strings.Contains(page, "No slides") { |
| + t.Errorf("the empty deck does not say it has no slides") |
| + } |
| +} |
| + |
| +// TestListSearchIsAGetFormOnTheTitle: ?q= narrows the list to titles |
| +// holding the words, as rows only; LIKE's wildcards are the words |
| +// themselves; and a search that finds nothing says so and offers the way |
| +// back. |
| +func TestListSearchIsAGetFormOnTheTitle(t *testing.T) { |
| + a := newApp(t) |
| + cookies := signedIn(t, a, allowedAddress) |
| + createDeck(t, a, cookies, "Hiring plan") |
| + createDeck(t, a, cookies, "Roadmap") |
| + createDeck(t, a, cookies, "Growth 100% plan") |
| + createDeck(t, a, cookies, "Growth 1000 ideas") |
| + |
| + list := mustGet(t, a, "/", http.StatusOK, cookies).Body.String() |
| + if !regexp.MustCompile(`<form slides-search method="get" action="/" role="search" data-busy="false">`).MatchString(list) { |
| + t.Errorf("the search is not a GET form exempt from the busy rule:\n%s", list) |
| + } |
| + |
| + found := mustGet(t, a, "/?q="+url.QueryEscape("PLAN"), http.StatusOK, cookies).Body.String() |
| + titles := rowLink.FindAllStringSubmatch(found, -1) |
| + if len(titles) != 2 || titles[0][2] != "Growth 100% plan" || titles[1][2] != "Hiring plan" { |
| + t.Errorf("?q=PLAN rows = %v, want the two plans, newest first", titles) |
| + } |
| + if strings.Contains(found, "slides-shelf") || strings.Contains(found, "Roadmap") { |
| + t.Errorf("a result page shows the shelf or a deck that does not match") |
| + } |
| + if !strings.Contains(found, `value="PLAN"`) { |
| + t.Errorf("the field does not hold what was searched for") |
| + } |
| + if !strings.Contains(found, "<title>Search: PLAN · Slides</title>") { |
| + t.Errorf("a result page's title does not name the search") |
| + } |
| + |
| + pct := mustGet(t, a, "/?q="+url.QueryEscape("100%"), http.StatusOK, cookies).Body.String() |
| + if got := rowLink.FindAllStringSubmatch(pct, -1); len(got) != 1 || got[0][2] != "Growth 100% plan" { |
| + t.Errorf("?q=100%% rows = %v, want only the deck with a percent sign", got) |
| + } |
| + |
| + none := mustGet(t, a, "/?q=zzz", http.StatusOK, cookies).Body.String() |
| + if !strings.Contains(none, "No decks match") || !strings.Contains(none, `<p slides-search-clear><a href="/">Clear search</a></p>`) { |
| + t.Errorf("a search that finds nothing does not say so with a way back:\n%s", none) |
| + } |
| +} |
| + |
| +// TestNewDeckNeedsNoTitleAndOpensTheEditor: the list's button is a form |
| +// with nothing in it but itself; it makes "Untitled deck" and lands in |
| +// the editor. GET /decks/new is the same button on its own page. |
| +func TestNewDeckNeedsNoTitleAndOpensTheEditor(t *testing.T) { |
| + a := newApp(t) |
| + cookies := signedIn(t, a, allowedAddress) |
| + |
| + list := mustGet(t, a, "/", http.StatusOK, cookies).Body.String() |
| + form := regexp.MustCompile(`(?s)<form slides-create method="post" action="/decks">(.*?)</form>`).FindStringSubmatch(list) |
| + if form == nil || strings.Contains(form[1], "<input") { |
| + t.Fatalf("the list's New deck is not a bare POST form:\n%s", list) |
| + } |
| + |
| + rec := post(t, a, "/decks", url.Values{}, cookies...) |
| + loc := rec.Header().Get("Location") |
| + path := deckPath.FindString(loc) |
| + if rec.Code != http.StatusSeeOther || path == "" || loc != path+"/edit" { |
| + t.Fatalf("POST /decks with nothing = %d to %q, want 303 to the editor", rec.Code, loc) |
| + } |
| + mustGet(t, a, loc, http.StatusOK, cookies) |
| + if page := mustGet(t, a, path, http.StatusOK, cookies).Body.String(); !strings.Contains(page, "Untitled deck") { |
| + t.Errorf("a deck made with no title is not called Untitled deck") |
| + } |
| + |
| + if rec := post(t, a, "/decks", url.Values{"theme": {"neon"}}, cookies...); rec.Code != http.StatusUnprocessableEntity || !strings.Contains(rec.Body.String(), "Pick one of the themes listed.") { |
| + t.Errorf("an unknown theme = %d, want 422 with the sentence", rec.Code) |
| + } |
| + |
| + page := mustGet(t, a, "/decks/new", http.StatusOK, cookies).Body.String() |
| + if !strings.Contains(page, `action="/decks"`) || strings.Contains(page, `name="title"`) || !strings.Contains(page, "Create deck") { |
| + t.Errorf("GET /decks/new is not one Create button:\n%s", page) |
| + } |
| +} |