Slides: a new deck needs no title and opens in the editor
Docs' "New document" (design/richer-ui), for decks. POST /decks takes
both fields as optional: no title makes "Untitled deck" (a catalog
string, slides.deck.untitled), no theme makes the default, and a theme
that is sent must still be one of the six (422 with the sentence). It
then lands in the editor, /d/{sqid}/edit, rather than the viewer: the
person who made a deck is there to write it.
GET /decks/new stays for a link or bookmark that points at it, as that
one Create button on a page of its own; the title field and the theme
picker are gone from it, since both are set in the editor.
Tests: the slidestest createDeck helper now requires the editor as the
Location and returns the deck's own /d/{sqid}; the browser drive of an
emptied deck starts from the Create button.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
5 files changed,
+51
−51
internal/slides/decks.go+26 −26internal/slides/locales/en.toml+6 −1internal/slides/templates/deck_new.html+8 −14internal/slidestest/browser_test.go+4 −5internal/slidestest/decks_test.go+7 −5
diff --git a/internal/slides/decks.go b/internal/slides/decks.go| index 68c6cec..46d3125 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" |
| @@ -845,18 +846,21 @@ func whenWords(r *http.Request, t time.Time) string { |
| // --- 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 +871,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 +903,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 +938,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/locales/en.toml b/internal/slides/locales/en.toml| index 8f0b451..26431d2 100644 |
| --- a/internal/slides/locales/en.toml |
| +++ b/internal/slides/locales/en.toml |
| @@ -91,7 +91,9 @@ 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. |
| @@ -128,6 +130,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/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/slidestest/browser_test.go b/internal/slidestest/browser_test.go| index f0b097c..944b36c 100644 |
| --- a/internal/slidestest/browser_test.go |
| +++ b/internal/slidestest/browser_test.go |
| @@ -720,13 +720,12 @@ func TestBrowserDeleteToEmptyThenNewSlide(t *testing.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.WaitVisible(`form[action="/decks"] button[type="submit"]`, chromedp.ByQuery), |
| + chromedp.Click(`form[action="/decks"] button[type="submit"]`, 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. |