Merge branch 'design/level-up-index' into design/level-up
13 files changed,
+1,251
−143
internal/slides/decks.go+264 −82internal/slides/decks_list_test.go+68 −0internal/slides/locales/en.toml+41 −12internal/slides/static/brand/decks.js+16 −0internal/slides/static/brand/light.css+154 −0internal/slides/static/brand/pointer.js+95 −0internal/slides/static/decks.css+333 −0internal/slides/team_access_test.go+4 −0internal/slides/templates/deck_new.html+8 −14internal/slides/templates/decks.html+82 −24internal/slidestest/browser_test.go+5 −6internal/slidestest/decks_test.go+7 −5internal/slidestest/list_test.go+174 −0
diff --git a/internal/slides/decks.go b/internal/slides/decks.go| index 68c6cec..9fdeba1 100644 |
| --- a/internal/slides/decks.go |
| +++ b/internal/slides/decks.go |
| @@ -15,6 +15,7 @@ import ( |
| "errors" |
| "fmt" |
| "net/http" |
| + "strings" |
| "time" |
| "github.com/go-chi/chi/v5" |
| @@ -26,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 --- |
| @@ -659,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 |
| @@ -684,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. |
| @@ -737,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). |
| @@ -792,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 { |
| @@ -843,20 +992,57 @@ 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 |
| +// first (Docs' "New document", 2026-11): the list's New deck button is a |
| +// form that POSTs here, and the deck is named "Untitled deck" until |
| +// somebody names it where they are working on it. GET /decks/new stays, |
| +// for a link or a bookmark that still points at it: a page with that |
| +// one button on it. |
| + |
| type deckNewPage struct { |
| shell |
| Title string |
| Body string |
| - TitleLabel string |
| - TitleValue string |
| - ThemeLabel string |
| - Themes []selectOption |
| Submit string |
| CancelHref string |
| CancelLabel string |
| - Errors map[string]string |
| + Error string |
| } |
| func (a *app) newDeck(w http.ResponseWriter, r *http.Request) { |
| @@ -867,28 +1053,29 @@ func (a *app) newDeck(w http.ResponseWriter, r *http.Request) { |
| if !a.teamMemberOnly(w, r, u) { |
| return |
| } |
| - render(w, "deck_new", a.newDeckPage(r, u, "", defaultTheme, nil)) |
| + render(w, "deck_new", a.newDeckPage(r, u, "")) |
| } |
| -func (a *app) newDeckPage(r *http.Request, u User, title, theme string, errs map[string]string) deckNewPage { |
| +func (a *app) newDeckPage(r *http.Request, u User, problem string) deckNewPage { |
| return deckNewPage{ |
| shell: a.shellFor(r, u, titled(rastrillo.T(r, "slides.decks.new"))), |
| Title: rastrillo.T(r, "slides.decks.new"), |
| Body: rastrillo.T(r, "slides.decks.new.body"), |
| - TitleLabel: rastrillo.T(r, "slides.deck.title.label"), |
| - TitleValue: title, |
| - ThemeLabel: rastrillo.T(r, "slides.deck.theme.label"), |
| - Themes: themeOptions(r, theme), |
| Submit: rastrillo.T(r, "slides.decks.new.submit"), |
| CancelHref: "/", |
| CancelLabel: rastrillo.T(r, "slides.cancel"), |
| - Errors: errs, |
| + Error: problem, |
| } |
| } |
| // createDeck serves POST /decks: the row, then the document's opening |
| // batch — the title and theme in meta, and one title slide carrying the |
| -// same words, so a new deck opens on something rather than on nothing. |
| +// same words, so a new deck opens on something rather than on nothing — |
| +// and then the editor. |
| +// |
| +// Both fields are optional. With no title (the list's button sends |
| +// none) the deck is "Untitled deck", in the reader's language; with no |
| +// theme it is the default. A theme that is sent must be one of the six. |
| func (a *app) createDeck(w http.ResponseWriter, r *http.Request) { |
| u, ok := a.viewer(w, r) |
| if !ok { |
| @@ -898,22 +1085,17 @@ func (a *app) createDeck(w http.ResponseWriter, r *http.Request) { |
| return |
| } |
| - p := form.Parse(r, form.Field{Name: "title", Required: true}) |
| - title := p.String("title") |
| + title := strings.TrimSpace(r.PostFormValue("title")) |
| + if title == "" { |
| + title = rastrillo.T(r, "slides.deck.untitled") |
| + } |
| theme := r.PostFormValue("theme") |
| - errs := map[string]string{} |
| - if !p.OK() { |
| - // The framework's own message is English built from the field |
| - // name; this app's every visible string is a catalog key, so |
| - // the failure is kept and the sentence replaced. |
| - errs["Title"] = rastrillo.T(r, "slides.deck.title.required") |
| + if theme == "" { |
| + theme = defaultTheme |
| } |
| if !validTheme(theme) { |
| - errs["Theme"] = rastrillo.T(r, "slides.deck.theme.invalid") |
| - } |
| - if len(errs) > 0 { |
| w.WriteHeader(http.StatusUnprocessableEntity) |
| - render(w, "deck_new", a.newDeckPage(r, u, p.Echo()["title"], theme, errs)) |
| + render(w, "deck_new", a.newDeckPage(r, u, rastrillo.T(r, "slides.deck.theme.invalid"))) |
| return |
| } |
| @@ -938,7 +1120,7 @@ func (a *app) createDeck(w http.ResponseWriter, r *http.Request) { |
| a.fail(w, r, "write the opening ops", err) |
| return |
| } |
| - http.Redirect(w, r, "/d/"+d.Sqid, http.StatusSeeOther) |
| + http.Redirect(w, r, "/d/"+d.Sqid+"/edit", http.StatusSeeOther) |
| } |
| // openingOps is a brand-new deck's first batch: meta, one flow slide on |
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 2b0d1e4..8bdc014 100644 |
| --- a/internal/slides/locales/en.toml |
| +++ b/internal/slides/locales/en.toml |
| @@ -91,31 +91,57 @@ slides.decks.empty.body = "A deck is a set of slides you write, present and shar |
| slides.decks.partial.title = "We couldn’t check your team access" |
| slides.decks.partial.body = "Only decks shared with you are shown. Try again in a moment for the rest." |
| slides.decks.new = "New deck" |
| -slides.decks.new.body = "Give it a name and a look. Both are easy to change later." |
| +# GET /decks/new is the list's New deck button on a page of its own: a |
| +# 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. |
| # |
| @@ -128,6 +154,9 @@ slides.deck.back = "Back to the deck" |
| slides.deck.slide = "Slide {n}" |
| slides.deck.title.label = "Title" |
| slides.deck.title.required = "Give the deck a title." |
| +# What a deck made with no title is called (POST /decks from the list's |
| +# New deck button) until somebody names it. |
| +slides.deck.untitled = "Untitled deck" |
| slides.deck.theme.label = "Theme" |
| slides.deck.theme.invalid = "Pick one of the themes listed." |
| slides.deck.rung.legend = "Who can open this deck" |
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/brand/light.css b/internal/slides/static/brand/light.css| new file mode 100644 |
| index 0000000..84e5031 |
| --- /dev/null |
| +++ b/internal/slides/static/brand/light.css |
| @@ -0,0 +1,154 @@ |
| +/* light.css — the light, for Slides: Docs' brand/light.css (design/ |
| + richer-ui, at "a press is press in and bloom, with no dark mark" and |
| + "every glow much fainter in dark mode"), on Slides' own attributes and |
| + accent. A page opts in by linking this and brand/pointer.js; nothing |
| + here does anything to a page that does not. |
| + |
| + The vocabulary, all opt-in, all generic: |
| + |
| + [slides-lit] a surface a pool of the accent's light follows the |
| + pointer across (a list row, a menu item, a panel), |
| + and a press blooms on. |
| + [slides-press] a control that gives a little under a press and |
| + springs back, overshooting slightly. Its scale is |
| + --slides-press-scale (0.965 by default). |
| + [slides-lift] a tile whose [slides-lift-face] (its picture) is |
| + picked up: it lifts toward the reader a little |
| + larger, takes the accent's edge, leans a few degrees |
| + toward the pointer, carries the light, and gives |
| + under a press. |
| + [rst-btn] rastrillo's buttons on such a page press in and |
| + bloom too: white on a filled button. This rastrillo |
| + has no press value or face layer of its own (Docs' |
| + newer one does), so the bloom rides here. |
| + |
| + Positions come from pointer.js: --rst-mx/--rst-my (the pointer, in |
| + the element's own pixels: rastrillo light.js's names, so one |
| + vocabulary lights both), --slides-tx/--slides-ty (the same, -1 to 1 |
| + across the element, for the lean), and --rst-px/--rst-py (where a |
| + press landed). Every one has a default here, so with no script the |
| + page is the still design. Hover light only under (hover: hover), so a |
| + touch screen never holds a light where a finger lifted; motion is |
| + dropped under reduced motion, where the edge alone says the same |
| + thing. |
| + |
| + In dark every glow is far fainter: light on a dark surface reads much |
| + brighter than on a light one (Paul, 2026-11-10). */ |
| +:root { |
| + /* The bloom's light, as an rgb triplet so its alpha can follow the |
| + press: rgb(var() / calc()) works in every engine, where a |
| + color-mix() whose percentage carried calc(var()) blanked Safari. |
| + Slides' accent (estilo theme/apps.go, hue 56), light and dark. */ |
| + --slides-bloom: 146 75 0; |
| + /* How strong every bloom is: 1 in light, much less in dark. */ |
| + --slides-bloom-k: 1; |
| + /* The pool of light a pointer casts on what it is over. */ |
| + --slides-light-tint: light-dark(color-mix(in srgb, var(--rst-accent) 10%, transparent), color-mix(in srgb, var(--rst-accent) 6%, transparent)); |
| +} |
| +/* Dark, a triplet, so a selector and a media query rather than |
| + light-dark(), which takes only colours. */ |
| +:root[data-theme="dark"] { --slides-bloom: 235 156 98; --slides-bloom-k: 0.4; } |
| +@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --slides-bloom: 235 156 98; --slides-bloom-k: 0.4; } } |
| + |
| +/* A press is press in and bloom: the control gives under the press and |
| + springs back on release; the light flares where the press landed, |
| + swelling while it is held and fading after release. --slides-press is |
| + 1 while held, at once, and falls to 0 over 0.7s, which a registered |
| + number can transition; the flare's size and alpha both ride it. |
| + Inherited, so a lifted tile's face reads its tile's press. */ |
| +@property --slides-press { |
| + syntax: "<number>"; |
| + inherits: true; |
| + initial-value: 0; |
| +} |
| +:root { |
| + --slides-flare: radial-gradient(calc(24px + var(--slides-press, 0) * 76px) circle at var(--rst-px, 50%) var(--rst-py, 50%), rgb(var(--slides-bloom) / calc(var(--slides-press, 0) * 0.16 * var(--slides-bloom-k))), transparent 72%); |
| + --slides-flare-on-fill: radial-gradient(calc(24px + var(--slides-press, 0) * 96px) circle at var(--rst-px, 50%) var(--rst-py, 50%), rgb(255 255 255 / calc(var(--slides-press, 0) * 0.22 * var(--slides-bloom-k))), transparent 72%); |
| + --slides-release: --slides-press 0.7s cubic-bezier(0.2, 0.6, 0.3, 1), scale 0.42s cubic-bezier(0.3, 1.6, 0.5, 1); |
| +} |
| + |
| +[slides-lit], |
| +[slides-press], |
| +[slides-lift], |
| +[rst-btn] { |
| + transition: var(--slides-release), background-color 150ms ease, border-color 150ms ease, color 150ms ease; |
| +} |
| +[slides-lit]:active, |
| +[slides-press]:active:not(:disabled):not([aria-disabled="true"]), |
| +[slides-lift]:active, |
| +[rst-btn]:active:not(:disabled):not([aria-busy="true"]) { |
| + --slides-press: 1; |
| + transition: scale 90ms ease-out; |
| +} |
| +[slides-press]:active:not(:disabled):not([aria-disabled="true"]) { scale: var(--slides-press-scale, 0.965); } |
| +[rst-btn]:active:not(:disabled):not([aria-busy="true"]) { scale: 0.965; } |
| +[slides-lit] { background-image: var(--slides-flare); } |
| +[slides-press]:not([slides-lit]), |
| +[rst-btn] { background-image: var(--slides-flare); } |
| +[rst-btn~="primary"], |
| +[rst-btn~="danger"] { background-image: var(--slides-flare-on-fill); } |
| + |
| +@media (hover: hover) { |
| + /* The second selector is a rastrillo row: its own hover fill is a |
| + background shorthand under a :has() that outweighs the first, and |
| + would take the light away exactly while the pointer is on it. */ |
| + [slides-lit]:hover, |
| + [rst-row][slides-lit]:has(> [rst-row-main] > a):hover { |
| + background-image: var(--slides-flare), radial-gradient(var(--slides-light-size, 280px) circle at var(--rst-mx, 50%) var(--rst-my, 50%), var(--slides-light-tint), transparent 70%); |
| + } |
| +} |
| + |
| +/* The lifted tile. The face is what moves: the tile itself (a link, |
| + title and all) stays where it is, so its hit area never slides out |
| + from under the pointer. The lean's transition is what makes it follow |
| + the pointer rather than jump. */ |
| +[slides-lift] [slides-lift-face] { |
| + position: relative; |
| + transition: transform 180ms cubic-bezier(.2, .7, .2, 1), box-shadow 180ms ease, scale 0.42s cubic-bezier(0.3, 1.6, 0.5, 1); |
| +} |
| +[slides-lift] [slides-lift-face]::after { |
| + content: ""; |
| + position: absolute; |
| + inset: 0; |
| + border-radius: inherit; |
| + background: |
| + var(--slides-flare), |
| + radial-gradient(180px circle at var(--rst-mx, 50%) var(--rst-my, 0%), var(--slides-light-tint), transparent 70%); |
| + opacity: 0; |
| + transition: opacity 200ms ease; |
| + pointer-events: none; |
| +} |
| +[slides-lift]:active [slides-lift-face]::after { |
| + opacity: 1; |
| +} |
| +[slides-lift]:hover [slides-lift-face], |
| +[slides-lift]:focus-visible [slides-lift-face] { |
| + transform: translateY(-6px) perspective(800px) |
| + rotateX(calc(var(--slides-ty, 0) * -4deg)) |
| + rotateY(calc(var(--slides-tx, 0) * 5deg)) |
| + scale(1.04); |
| + 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)); |
| +} |
| +[slides-lift]:active [slides-lift-face] { |
| + scale: 0.97; |
| + transition: transform 180ms cubic-bezier(.2, .7, .2, 1), box-shadow 180ms ease, scale 90ms ease-out; |
| +} |
| +@media (hover: hover) { |
| + [slides-lift]:hover [slides-lift-face]::after { |
| + opacity: 1; |
| + } |
| +} |
| + |
| +@media (prefers-reduced-motion: reduce) { |
| + [slides-press]:active, [rst-btn]:active, [slides-lift]:active [slides-lift-face] { scale: none; } |
| + [slides-lift] [slides-lift-face] { transition: none; } |
| + [slides-lift]:hover [slides-lift-face], |
| + [slides-lift]:focus-visible [slides-lift-face] { transform: none; } |
| +} |
| +@media (forced-colors: active) { |
| + [slides-lit], [slides-press], [rst-btn] { background-image: none; } |
| + [slides-lift] [slides-lift-face]::after { content: none; } |
| +} |
diff --git a/internal/slides/static/brand/pointer.js b/internal/slides/static/brand/pointer.js| new file mode 100644 |
| index 0000000..d8404b3 |
| --- /dev/null |
| +++ b/internal/slides/static/brand/pointer.js |
| @@ -0,0 +1,95 @@ |
| +/* pointer.js — Slides' half of the light: Docs' brand/pointer.js |
| + (design/richer-ui), on Slides' opt-in attributes. brand/light.css |
| + says what each attribute does; this only tells it where the pointer |
| + is. |
| + |
| + What it writes, on the one lit element under the pointer, and |
| + nothing else: --rst-mx and --rst-my, the pointer in the element's own |
| + pixels (rastrillo light.js's names and units, so one stylesheet |
| + vocabulary lights both), and --slides-tx and --slides-ty, the same |
| + position from -1 to 1 across the element, for a lifted tile's lean. |
| + It clears them when the pointer leaves. A press writes where it |
| + landed as --rst-px and --rst-py on the control, light.js's names |
| + again, which the bloom is centred on. Every property has a default in |
| + the stylesheet, so deleting this file and its tag leaves the still |
| + design. |
| + |
| + Lit is [slides-lit], [slides-lift], [slides-press] and [rst-btn], |
| + and any element that is lit through a parent is lit as that parent: |
| + it takes the nearest. It never runs for touch, under reduced motion |
| + or forced colours, or without a hovering pointer; one animation |
| + frame per move at most. */ |
| +(function () { |
| + "use strict"; |
| + if (!window.matchMedia || !window.requestAnimationFrame) return; |
| + var LIT = "[slides-lit],[slides-lift],[slides-press],[rst-btn]"; |
| + var PROPS = ["--rst-mx", "--rst-my", "--slides-tx", "--slides-ty"]; |
| + var quiet = [matchMedia("(prefers-reduced-motion: reduce)"), matchMedia("(forced-colors: active)")]; |
| + var hover = matchMedia("(hover: hover)"); |
| + var lit = null, pending = null, raf = 0, listening = false; |
| + |
| + function mouse(e) { |
| + return !e.pointerType || e.pointerType === "mouse" || e.pointerType === "pen"; |
| + } |
| + function litFrom(target) { |
| + return target && target.closest ? target.closest(LIT) : null; |
| + } |
| + function clear() { |
| + if (!lit) return; |
| + for (var i = 0; i < PROPS.length; i++) lit.style.removeProperty(PROPS[i]); |
| + lit = null; |
| + } |
| + function step() { |
| + raf = 0; |
| + var e = pending; |
| + pending = null; |
| + if (!e) return; |
| + var el = litFrom(e.target); |
| + if (el !== lit) clear(); |
| + if (!el) return; |
| + lit = el; |
| + var r = el.getBoundingClientRect(); |
| + if (!r.width || !r.height) return; |
| + var x = e.clientX - r.left, y = e.clientY - r.top; |
| + el.style.setProperty("--rst-mx", x.toFixed(0) + "px"); |
| + el.style.setProperty("--rst-my", y.toFixed(0) + "px"); |
| + el.style.setProperty("--slides-tx", Math.max(-1, Math.min(1, (x / r.width) * 2 - 1)).toFixed(3)); |
| + el.style.setProperty("--slides-ty", Math.max(-1, Math.min(1, (y / r.height) * 2 - 1)).toFixed(3)); |
| + } |
| + function move(e) { |
| + if (!mouse(e)) return; |
| + pending = e; |
| + if (!raf) raf = requestAnimationFrame(step); |
| + } |
| + function out(e) { |
| + if (!e.relatedTarget) clear(); |
| + } |
| + function press(e) { |
| + if (e.button !== 0 || !mouse(e)) return; |
| + var el = litFrom(e.target); |
| + if (!el || el.disabled) return; |
| + var r = el.getBoundingClientRect(); |
| + el.style.setProperty("--rst-px", (e.clientX - r.left).toFixed(0) + "px"); |
| + el.style.setProperty("--rst-py", (e.clientY - r.top).toFixed(0) + "px"); |
| + } |
| + function sync() { |
| + var want = hover.matches && !quiet[0].matches && !quiet[1].matches; |
| + if (want === listening) return; |
| + listening = want; |
| + if (want) { |
| + document.addEventListener("pointermove", move, { passive: true }); |
| + document.addEventListener("pointerout", out, { passive: true }); |
| + document.addEventListener("pointerdown", press, { passive: true }); |
| + } else { |
| + document.removeEventListener("pointermove", move); |
| + document.removeEventListener("pointerout", out); |
| + document.removeEventListener("pointerdown", press); |
| + clear(); |
| + } |
| + } |
| + [hover, quiet[0], quiet[1]].forEach(function (m) { |
| + if (m.addEventListener) m.addEventListener("change", sync); |
| + else if (m.addListener) m.addListener(sync); |
| + }); |
| + sync(); |
| +})(); |
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/deck_new.html b/internal/slides/templates/deck_new.html| index 4bc3109..90f3dbe 100644 |
| --- a/internal/slides/templates/deck_new.html |
| +++ b/internal/slides/templates/deck_new.html |
| @@ -1,21 +1,15 @@ |
| -{{/* deck_new — GET /decks/new, the create form and nothing else. |
| - |
| - One form, one primary button, a cancel that is a real link. Both |
| - controls come from ui: a hand-rolled <label><input> validates fine |
| - and renders as ragged inline labels over an unstyled button, which |
| - is exactly the failure nothing tells you about. */}} |
| +{{/* deck_new — GET /decks/new, for a link or a bookmark that still |
| + points here. A new deck needs nothing asked first (decks.go's |
| + createDeck: "Untitled deck", the default theme, then the editor), |
| + so this page is the list's New deck button on its own: one form, |
| + one primary button, a cancel that is a real link. It also carries |
| + the one refusal POST /decks can make of a browser, a theme that is |
| + not one of the six, which only a hand-made request can send. */}} |
| {{define "content"}} |
| {{template "page-header" dict "Title" .Title "Sub" .Body}} |
| <div rst-box> |
| + {{with .Error}}{{template "callout" dict "Tone" "negative" "Body" .}}{{end}} |
| <form rst-form method="post" action="/decks"> |
| - {{template "field-text" dict |
| - "Name" "title" "Label" .TitleLabel "Value" .TitleValue |
| - "Required" true "Primary" true "Autofocus" true |
| - "Error" (index .Errors "Title")}} |
| - {{template "field-select" dict |
| - "ID" "theme" "Name" "theme" "Label" .ThemeLabel |
| - "Options" .Themes "Required" true |
| - "Error" (index .Errors "Theme")}} |
| {{template "form-foot" dict |
| "Submit" .Submit "CancelHref" .CancelHref "CancelLabel" .CancelLabel}} |
| </form> |
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 f96ca5c..d6ed0ab 100644 |
| --- a/internal/slidestest/browser_test.go |
| +++ b/internal/slidestest/browser_test.go |
| @@ -719,14 +719,13 @@ func TestBrowserDeleteToEmptyThenNewSlide(t *testing.T) { |
| rig, mailer := newRig(t) |
| browserSignIn(t, rig, mailer) |
| rig.Run( |
| - chromedp.Navigate(rig.Origin+"/decks/new"), |
| - chromedp.WaitVisible(`input[name="title"]`, chromedp.ByQuery), |
| - chromedp.SendKeys(`input[name="title"]`, "Empty me", chromedp.ByQuery), |
| - chromedp.Submit(`input[name="title"]`, chromedp.ByQuery), |
| - waitFor(`/^\/d\/[^/]+$/.test(location.pathname)`), |
| + 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 |
| - rig.Run(chromedp.Evaluate(`location.pathname`, &deck)) |
| + rig.Run(chromedp.Evaluate(`location.pathname.replace(/\/edit$/, "")`, &deck)) |
| const saved = `document.querySelector('[estilo-save-status]').dataset.state === 'saved'` |
| rig.Run( |
diff --git a/internal/slidestest/decks_test.go b/internal/slidestest/decks_test.go| index 5b7b304..88bfa01 100644 |
| --- a/internal/slidestest/decks_test.go |
| +++ b/internal/slidestest/decks_test.go |
| @@ -28,8 +28,9 @@ func newSharedApp(t *testing.T) *testApp { |
| return newAppWith(t, cfg, mailer) |
| } |
| -// createDeck posts the new-deck form and returns the sqid path the app |
| -// redirected to. |
| +// createDeck posts a new deck and returns its /d/{sqid} path. A new deck |
| +// opens in the editor, so the app redirects to /d/{sqid}/edit; the deck's |
| +// own path is what every caller builds on. |
| func createDeck(t *testing.T, a *testApp, cookies []*http.Cookie, title string) string { |
| t.Helper() |
| rec := post(t, a, "/decks", url.Values{"title": {title}, "theme": {"ink"}}, cookies...) |
| @@ -37,10 +38,11 @@ func createDeck(t *testing.T, a *testApp, cookies []*http.Cookie, title string) |
| t.Fatalf("POST /decks: status %d, want %d\n%s", rec.Code, http.StatusSeeOther, rec.Body) |
| } |
| loc := rec.Header().Get("Location") |
| - if !deckPath.MatchString(loc) { |
| - t.Fatalf("POST /decks: Location = %q, want a /d/{sqid}", loc) |
| + path := deckPath.FindString(loc) |
| + if path == "" || loc != path+"/edit" { |
| + t.Fatalf("POST /decks: Location = %q, want a /d/{sqid}/edit", loc) |
| } |
| - return loc |
| + return path |
| } |
| // mustGet fetches target and fails unless the status is want. |
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) |
| + } |
| +} |