Dock Ask Base beside Home, open by default
Home becomes the mockup's shell: the header across the top, Home on the left and Ask Base docked on the right under it, open unless the member closed it (members.ask_closed, migration 0011; <html class="desk-closed">). The X, the Base button and the greeting's field are forms posting POST /ask/dock, which the script sends by fetch. "/" opens the chat or focuses its composer. Phones keep the springboard and the full-screen chat, not remembered. Transform and opacity only; reduced motion stops it. Without Equipo, Home has no chat, Base button or field. The popover, its placement and the dialog go. No new words; copy-pending notes the reuse and the removed tooltip.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
19 files changed,
+745
−287
docs/copy-pending.md+4 −1internal/browsertest/ask_test.go+166 −43internal/browsertest/layout_test.go+32 −46internal/browsertest/light_test.go+9 −7internal/browsertest/mobile_test.go+71 −19internal/browsertest/scroll_test.go+4 −4internal/look/static/app.css+99 −74internal/look/static/ask.js+104 −65internal/look/templates/layout.html+2 −2internal/store/askdock.go+22 −0internal/store/askdock_test.go+58 −0internal/store/members.go+5 −2internal/store/migrations/0011_ask_closed.sql+3 −0internal/web/ask.go+28 −0internal/web/home.go+10 −4internal/web/templates/home.html+14 −10internal/web/templates/partials/chat.html+4 −4internal/webtest/ask_test.go+5 −3internal/webtest/home_test.go+105 −3
diff --git a/docs/copy-pending.md b/docs/copy-pending.md| index b456b3b..b3cd483 100644 |
| --- a/docs/copy-pending.md |
| +++ b/docs/copy-pending.md |
| @@ -362,8 +362,11 @@ Review 8 (approved 2026-11-13): Base never names Equipo in the chat, setup or Se |
| | settings.html | CHANGED (Review 8): the row's value before setup | ~~Not connected~~ → Not set up | |
| | partials/chat.html | REMOVED (D12, the ⋯ menu goes; Base never sends the person into Equipo as a step): the Ask panel header's ⋯ menu and its link | ~~Open Equipo~~ | |
| -Pending review (not part of Review 8): D12's reuse of the chat's lead on the setup page. |
| +Pending review (not part of Review 8): D12's reuse of the chat's lead on the setup page, and D18's docked chat on Home (no new words: approved ones reused, one removed). |
| | File | Context | Text | |
| |---|---|---| |
| | ask_connect.html | PENDING: the setup page's lead before setup reuses the chat's approved lead, so the page and the chat say the same words | Set up Ask Base to start asking. | |
| +| home.html | PENDING (D18): the header's Base button, which opens the docked chat; its name, now also its tooltip, is the approved label of the Ask icon it replaces | Ask Base | |
| +| home.html | PENDING (D18): the field under the greeting that opens the chat, with its "/" hint; the approved placeholder, now on a button | Ask Base anything | |
| +| home.html | REMOVED (D18): with Ask off Home has no field, so the disabled field and its tooltip go | ~~Asking Base arrives in a later slice~~ | |
diff --git a/internal/browsertest/ask_test.go b/internal/browsertest/ask_test.go| index d3cf565..221b09d 100644 |
| --- a/internal/browsertest/ask_test.go |
| +++ b/internal/browsertest/ask_test.go |
| @@ -12,6 +12,8 @@ import ( |
| "testing" |
| "time" |
| + "github.com/chromedp/cdproto/cdp" |
| + "github.com/chromedp/cdproto/input" |
| "github.com/chromedp/chromedp" |
| "amadan.net/rastrillo/rastrillo/harness" |
| @@ -20,22 +22,6 @@ import ( |
| "amadan.net/carlos/base/internal/equipo/equipotest" |
| ) |
| -// With the chat off, the Ask field is drawn as glass, not a native |
| -// disabled input with its bevel. |
| -func TestAskFieldOffIsGlass(t *testing.T) { |
| - var b *baseApp |
| - rig := newRig(t, func(origin string) http.Handler { |
| - b = newBase(t, baseConfig(origin)) |
| - return b.handler |
| - }) |
| - signInByEmail(t, rig, rig.Origin, b.mail) |
| - style := harness.Evaluate[string](rig, `(() => { const s = getComputedStyle(document.querySelector("input.ask")); |
| - return [s.borderTopStyle, s.borderTopWidth, s.boxShadow === "none" ? "flat" : "glass"].join(" ") })()`) |
| - if style != "none 0px glass" { |
| - t.Fatalf("the off Ask field is drawn %q, want %q", style, "none 0px glass") |
| - } |
| -} |
| - |
| // askBase is Base answered by a fake Equipo, the owner signed in and |
| // connected to it from Settings: Set up Ask Base, approve the code in |
| // Equipo, Check again. |
| @@ -97,11 +83,52 @@ func askBaseOn(t *testing.T, tweak func(*config.Config), view chromedp.Action[ch |
| return rig, f, b |
| } |
| -// openPanel opens the panel from Home's Ask field. |
| +// settledJS is true once the docked chat is open and done moving. |
| +const settledJS = `(() => { const d = document.querySelector("#ask-panel"), s = getComputedStyle(d); |
| + return d.checkVisibility({ visibilityProperty: true }) && s.opacity === "1" && (s.transform === "none" || s.transform === "matrix(1, 0, 0, 1, 0, 0)"); })()` |
| + |
| +// openPanel goes to Home, where on a wide screen Ask Base is docked open, |
| +// and waits for the chat to settle. |
| func openPanel(t *testing.T, rig *harness.Rig) { |
| t.Helper() |
| - drive(t, rig, chromedp.Navigate(rig.Origin+"/"), chromedp.WaitVisible(chromedp.CSS(`a.ask`)), |
| - chromedp.Click(chromedp.CSS(`a.ask`)), chromedp.WaitVisible(chromedp.CSS(`#ask-panel textarea`))) |
| + drive(t, rig, chromedp.Navigate(rig.Origin+"/"), chromedp.WaitVisible(chromedp.CSS(`#ask-panel textarea`)), |
| + chromedp.Poll[chromedp.Void](settledJS, chromedp.WithPollingTimeout(5*time.Second))) |
| +} |
| + |
| +// slash presses "/" as a keyboard does: one keydown carrying the text, so |
| +// a page that handles the keydown types nothing. |
| +func slash() chromedp.Action[chromedp.Void] { |
| + return chromedp.Func(func(ctx context.Context, target *chromedp.Target) error { |
| + for _, typ := range []input.DispatchKeyEventType{input.DispatchKeyEventTypeKeyDown, input.DispatchKeyEventTypeKeyUp} { |
| + k := input.DispatchKeyEventParams{Type: typ, Key: "/", Code: "Slash", WindowsVirtualKeyCode: 191, NativeVirtualKeyCode: 191} |
| + if typ == input.DispatchKeyEventTypeKeyDown { |
| + k.Text, k.UnmodifiedText = "/", "/" |
| + } |
| + if _, err := cdp.Call(ctx, target, input.DispatchKeyEvent, k); err != nil { |
| + return err |
| + } |
| + } |
| + return nil |
| + }) |
| +} |
| + |
| +// askClosed waits until the member's close of the docked chat is kept (or |
| +// its reopening, for false): the script posts it by fetch. |
| +func askClosed(t *testing.T, b *baseApp, want bool) { |
| + t.Helper() |
| + for i := 0; ; i++ { |
| + var closed bool |
| + if err := b.db.QueryRow(`SELECT ask_closed FROM members ORDER BY invited_at LIMIT 1`).Scan(&closed); err != nil { |
| + t.Fatal(err) |
| + } |
| + if closed == want { |
| + return |
| + } |
| + if i > 100 { |
| + t.Fatalf("ask_closed is %v, want %v", closed, want) |
| + } |
| + time.Sleep(20 * time.Millisecond) |
| + } |
| } |
| // A double press sends once, and sending again after an answer was lost |
| @@ -180,8 +207,8 @@ func TestAskPanelStatesShowApprovedWords(t *testing.T) { |
| .filter(el => el.checkVisibility()).map(el => el.dataset.when + "=" + el.textContent.replace(/\s+/g, " ").trim()).join("|")`) |
| } |
| openOnly := func(rig *harness.Rig, when string) { |
| - drive(t, rig, chromedp.Navigate(rig.Origin+"/"), chromedp.WaitVisible(chromedp.CSS(`a.ask`)), |
| - chromedp.Click(chromedp.CSS(`a.ask`)), chromedp.WaitVisible(chromedp.CSS(`#ask-panel .ask-note[data-when="`+when+`"], #ask-panel .ask-runner[data-when="`+when+`"]`))) |
| + drive(t, rig, chromedp.Navigate(rig.Origin+"/"), |
| + chromedp.WaitVisible(chromedp.CSS(`#ask-panel .ask-note[data-when="`+when+`"], #ask-panel .ask-runner[data-when="`+when+`"]`))) |
| } |
| t.Run("unavailable", func(t *testing.T) { |
| rig, f := askBase(t) |
| @@ -221,23 +248,50 @@ func keys(calls []equipotest.Call) []string { |
| return out |
| } |
| -// The owner opens the panel from Home, asks one thing and sees the |
| -// coordinator's reply stream in; Escape closes the panel and gives focus |
| -// back to the field. |
| -func TestAskPanel(t *testing.T) { |
| +// On a wide screen Home opens with Ask Base docked open on the right, from |
| +// under the header to the foot of the screen, beside Home; the greeting's |
| +// field has folded away and the Base button is hidden. The owner asks one |
| +// thing and sees the reply stream in, and "/" puts focus in the composer |
| +// from anywhere but a field. |
| +func TestAskDockedOpenByDefault(t *testing.T) { |
| rig, f := askBase(t) |
| openPanel(t, rig) |
| + if got := harness.Evaluate[string](rig, `(() => { |
| + const problems = [], vw = document.documentElement.clientWidth, vh = innerHeight; |
| + const p = document.querySelector("#ask-panel").getBoundingClientRect(), bar = document.querySelector(".topbar").getBoundingClientRect(); |
| + const home = document.querySelector("main.home").getBoundingClientRect(), apps = document.querySelector("nav.apps").getBoundingClientRect(); |
| + const w = Math.min(440, Math.max(360, vw * 0.3)); |
| + if (Math.abs(p.width - w) > 1) problems.push("width " + p.width + ", want " + w); |
| + if (p.top < bar.bottom || p.top > bar.bottom + 24) problems.push("top " + p.top + ", the header ends at " + bar.bottom); |
| + if (p.bottom > vh || vh - p.bottom > 24) problems.push("bottom " + p.bottom + " of " + vh); |
| + if (p.right > vw || vw - p.right > 24) problems.push("right " + p.right + " of " + vw); |
| + if (p.left < home.right - 0.5 || p.left < apps.right) problems.push("left " + p.left + ", Home ends at " + home.right + ", the apps at " + apps.right); |
| + if (document.documentElement.classList.contains("desk-closed")) problems.push("drawn closed"); |
| + const field = document.querySelector(".ask-field"), btn = document.querySelector(".base-btn"); |
| + if (field.checkVisibility({ visibilityProperty: true }) || !field.closest(".ask-slot").inert) problems.push("the greeting's field shows"); |
| + if (btn.checkVisibility({ visibilityProperty: true })) problems.push("the Base button shows"); |
| + if (document.documentElement.scrollWidth > vw) problems.push("page overflows"); |
| + return problems.join("; "); |
| + })()`); got != "" { |
| + t.Errorf("the docked chat at 1280x800: %s", got) |
| + } |
| if here := harness.Read(rig, chromedp.Location()); here != rig.Origin+"/" { |
| - t.Fatalf("the field navigated to %s instead of opening the panel", here) |
| + t.Fatalf("Home moved to %s", here) |
| } |
| - if got := harness.Evaluate[string](rig, `document.activeElement.id`); got != "ask-text" { |
| - t.Errorf("focus is on %q, want the message field", got) |
| + // "/" from anywhere but a field puts focus in the composer. |
| + drive(t, rig, chromedp.Evaluate[chromedp.Void](`document.activeElement.blur()`), slash()) |
| + if got := harness.Evaluate[string](rig, `document.activeElement.id + "|" + document.querySelector("#ask-text").value`); got != "ask-text|" { |
| + t.Errorf(`after "/" focus and the field are %q, want the empty message field`, got) |
| } |
| - drive(t, rig, chromedp.SendKeys(chromedp.CSS(`#ask-text`), "What can I do"), |
| + drive(t, rig, chromedp.SendKeys(chromedp.CSS(`#ask-text`), "What can I do"), slash()) |
| + if got := harness.Evaluate[string](rig, `document.querySelector("#ask-text").value`); got != "What can I do/" { |
| + t.Errorf(`"/" in the field typed %q`, got) |
| + } |
| + drive(t, rig, chromedp.Evaluate[chromedp.Void](`document.querySelector("#ask-text").value = "What can I do"`), |
| chromedp.Click(chromedp.CSS(`#ask-panel form.composer button`)), |
| chromedp.Poll[chromedp.Void](`[...document.querySelectorAll("#ask-panel .msg.coordinator")].some(m => m.textContent.includes("What would you like to do?") && !m.classList.contains("draft"))`, |
| chromedp.WithPollingTimeout(10*time.Second))) |
| - rig.Screen("#ask-panel", "the panel with one question answered") |
| + rig.Screen("#ask-panel", "the docked chat with one question answered") |
| if got := harness.Evaluate[int](rig, `document.querySelectorAll("#ask-panel .msg.person").length`); got != 1 { |
| t.Errorf("person messages shown: %d", got) |
| } |
| @@ -263,22 +317,91 @@ func TestAskPanel(t *testing.T) { |
| if harness.Evaluate[bool](rig, `!!document.querySelector("#ask-panel .ask-head summary, #ask-panel .ask-head a")`) { |
| t.Error("the panel's header still has a menu or a link") |
| } |
| +} |
| + |
| +// The X slides the docked chat out and Home takes the width (the apps grid |
| +// gains a column); the Base button shows, with focus. A reload keeps it |
| +// closed. The Base button, or "/", brings it back, and a reload keeps it |
| +// open. With reduced motion it opens and closes without moving. |
| +func TestAskDockClosePersists(t *testing.T) { |
| + apps := teamApps(t) |
| + rig, _, b := askBaseWith(t, func(c *config.Config) { c.OficinaApps = apps }) |
| + installAll(t, b) |
| + drive(t, rig, chromedp.EmulateViewport(900, 800)) |
| + openPanel(t, rig) |
| + appsRight := func() float64 { |
| + return harness.Evaluate[float64](rig, `document.querySelector("nav.apps").getBoundingClientRect().right`) |
| + } |
| + gone := `(() => { const d = document.querySelector("#ask-panel"); return document.documentElement.classList.contains("desk-closed") && !d.checkVisibility({ visibilityProperty: true }) })()` |
| + closedJS := `(() => { const problems = [], vw = document.documentElement.clientWidth; |
| + if (!document.documentElement.classList.contains("desk-closed")) problems.push("not desk-closed"); |
| + if (document.querySelector("#ask-panel").checkVisibility({ visibilityProperty: true })) problems.push("the chat shows"); |
| + if (!document.querySelector("#ask-panel").inert) problems.push("the chat is not inert"); |
| + if (!document.querySelector(".base-btn").checkVisibility({ visibilityProperty: true })) problems.push("no Base button"); |
| + if (!document.querySelector(".ask-field").checkVisibility({ visibilityProperty: true })) problems.push("no field under the greeting"); |
| + const home = document.querySelector("main.home").getBoundingClientRect(); |
| + if (vw - home.right > 1) problems.push("Home ends at " + home.right + " of " + vw); |
| + return problems.join("; "); })()` |
| + open := appsRight() |
| + |
| + drive(t, rig, chromedp.Click(chromedp.CSS(`#ask-panel .ask-head button.close`)), |
| + chromedp.Poll[chromedp.Void](gone, chromedp.WithPollingTimeout(3*time.Second))) |
| + if got := harness.Evaluate[string](rig, closedJS); got != "" { |
| + t.Errorf("closed: %s", got) |
| + } |
| + if got := appsRight(); got <= open+48 { |
| + t.Errorf("closed, the apps end at %v, open at %v: Home did not take the width", got, open) |
| + } |
| + if got := harness.Evaluate[string](rig, `document.activeElement.className`); got != "base-btn" { |
| + t.Errorf("after X focus is on %q, want the Base button", got) |
| + } |
| + askClosed(t, b, true) |
| + layoutShot(t, rig, "desktop-chat-closed-dark") |
| - // The next Escape closes the panel. |
| - drive(t, rig, chromedp.KeyEvent("\u001b"), |
| - chromedp.Poll[chromedp.Void](`!document.querySelector("#ask-panel").open`, chromedp.WithPollingTimeout(5*time.Second))) |
| - if got := harness.Evaluate[string](rig, `document.activeElement.className`); got != "ask" { |
| - t.Errorf("after Escape focus is on %q, want the Ask field", got) |
| + // Reloaded, it is closed from the first paint. |
| + drive(t, rig, chromedp.Navigate(rig.Origin+"/"), chromedp.WaitVisible(chromedp.CSS(".base-btn"))) |
| + if got := harness.Evaluate[string](rig, closedJS); got != "" { |
| + t.Errorf("reloaded: %s", got) |
| } |
| - // On a phone the panel is the whole screen. |
| - drive(t, rig, chromedp.EmulateViewport(390, 844), chromedp.Click(chromedp.CSS(`a.ask-icon`)), |
| - chromedp.WaitVisible(chromedp.CSS(`#ask-panel textarea`))) |
| - rig.Screen("#ask-panel", "the panel on a phone") |
| - // Once it has slid in, it covers the screen. |
| - whole := `(() => { const r = document.querySelector("#ask-panel").getBoundingClientRect(); |
| - return [r.left, r.top, r.width, r.height].map(Math.round).join(" ") === "0 0 390 844" })()` |
| - drive(t, rig, chromedp.Poll[chromedp.Void](whole, chromedp.WithPollingTimeout(3*time.Second))) |
| + // The Base button reopens it, focus in the composer; a reload keeps it. |
| + drive(t, rig, chromedp.Click(chromedp.CSS(".base-btn")), chromedp.Poll[chromedp.Void](settledJS, chromedp.WithPollingTimeout(3*time.Second))) |
| + if got := harness.Evaluate[string](rig, `document.activeElement.id`); got != "ask-text" { |
| + t.Errorf("reopened, focus is on %q, want the message field", got) |
| + } |
| + askClosed(t, b, false) |
| + openPanel(t, rig) |
| + if harness.Evaluate[bool](rig, `document.documentElement.classList.contains("desk-closed")`) { |
| + t.Error("reopened and reloaded, it is closed") |
| + } |
| + |
| + // Closed again, "/" reopens it. |
| + drive(t, rig, chromedp.Click(chromedp.CSS(`#ask-panel .ask-head button.close`)), |
| + chromedp.Poll[chromedp.Void](gone, chromedp.WithPollingTimeout(3*time.Second))) |
| + askClosed(t, b, true) |
| + drive(t, rig, chromedp.Navigate(rig.Origin+"/"), chromedp.WaitVisible(chromedp.CSS(".base-btn")), |
| + slash(), chromedp.Poll[chromedp.Void](settledJS, chromedp.WithPollingTimeout(3*time.Second))) |
| + if got := harness.Evaluate[string](rig, `document.activeElement.id`); got != "ask-text" { |
| + t.Errorf(`opened by "/", focus is on %q`, got) |
| + } |
| + askClosed(t, b, false) |
| + openPanel(t, rig) |
| + |
| + // With reduced motion nothing moves: it just goes, and just comes back. |
| + drive(t, rig, reducedMotion("dark", true)) |
| + if got := harness.Evaluate[string](rig, `getComputedStyle(document.querySelector("#ask-panel")).transitionDuration`); got != "0s" { |
| + t.Errorf("with reduced motion the chat's transition-duration is %q, want 0s", got) |
| + } |
| + drive(t, rig, chromedp.Click(chromedp.CSS(`#ask-panel .ask-head button.close`))) |
| + if !harness.Evaluate[bool](rig, gone) { |
| + t.Error("with reduced motion the chat did not close at once") |
| + } |
| + drive(t, rig, chromedp.Click(chromedp.CSS(".base-btn"))) |
| + if !harness.Evaluate[bool](rig, settledJS) { |
| + t.Error("with reduced motion the chat did not open at once") |
| + } |
| + drive(t, rig, reducedMotion("dark", false)) |
| + askClosed(t, b, false) |
| } |
| // The composer is the familiar one: no Send until something is typed, then |
diff --git a/internal/browsertest/layout_test.go b/internal/browsertest/layout_test.go| index 51722bb..e9fbc2c 100644 |
| --- a/internal/browsertest/layout_test.go |
| +++ b/internal/browsertest/layout_test.go |
| @@ -154,7 +154,7 @@ const springboardJS = `((want) => { |
| if (r.left < p.left || r.right > p.right) problems.push(a.textContent.trim() + " is outside the panel"); |
| } |
| if (document.querySelector(".dock")) problems.push("there is still a dock"); |
| - const fixed = [...document.querySelectorAll("main *")].filter(e => getComputedStyle(e).position === "fixed" && e.checkVisibility() && !e.closest("dialog")); |
| + const fixed = [...document.querySelectorAll("main *")].filter(e => getComputedStyle(e).position === "fixed" && e.checkVisibility() && !e.closest(".chat-col")); |
| if (fixed.length) problems.push("fixed: " + fixed.map(e => e.className).join(", ")); |
| window.scrollTo(0, document.documentElement.scrollHeight); |
| const last = grid[grid.length - 1].getBoundingClientRect(); |
| @@ -192,86 +192,72 @@ func TestHomeApps(t *testing.T) { |
| } |
| } |
| // The keyboard: the top bar, then every app, Base's own pages last. |
| + // With the chat docked open the Base button and the greeting's field |
| + // are out of reach. |
| drive(t, rig, chromedp.EmulateViewport(1280, 800), chromedp.Navigate(rig.Origin+"/"), chromedp.WaitVisible(chromedp.CSS("nav.apps"))) |
| var seen []string |
| for range 3 + len(apps) + 2 + 3 { |
| drive(t, rig, chromedp.KeyEvent("\t")) |
| seen = append(seen, harness.Evaluate[string](rig, `document.activeElement.matches(":focus-visible") ? document.activeElement.textContent.trim() : "(no visible focus)"`)) |
| } |
| - want := append(append([]string{"Ask Base anything", "PC"}, append(names(apps), "Scratchpad", "Welcome")...), "Store", "People", "Settings") |
| + want := append(append([]string{"PC"}, append(names(apps), "Scratchpad", "Welcome")...), "Store", "People", "Settings") |
| if fmt.Sprint(seen[:len(want)]) != fmt.Sprint(want) && fmt.Sprint(seen[1:len(want)+1]) != fmt.Sprint(want) { |
| t.Errorf("Tab visits %v, want %v", seen, want) |
| } |
| } |
| -// popoverJS checks the chat on a wide screen: a popover under the Ask |
| -// field, about 440px wide and min(640px, the screen less 120px) tall, inside |
| -// the screen, with its pointer over the field. |
| -const popoverJS = `(() => { |
| +// dockedJS checks the chat on a wide screen: docked on the right under the |
| +// header and down to the foot of the screen, clamp(360px, 30vw, 440px) |
| +// wide, beside Home and its apps, inside the screen. |
| +const dockedJS = `(() => { |
| const problems = [], vw = document.documentElement.clientWidth, vh = innerHeight; |
| - const d = document.querySelector("#ask-panel"), r = d.getBoundingClientRect(); |
| - const f = document.querySelector("a.ask").getBoundingClientRect(); |
| - const w = Math.min(440, vw - 24), h = Math.min(640, vh - 120); |
| + const r = document.querySelector("#ask-panel").getBoundingClientRect(), bar = document.querySelector(".topbar").getBoundingClientRect(); |
| + const home = document.querySelector("main.home").getBoundingClientRect(), apps = document.querySelector("nav.apps").getBoundingClientRect(); |
| + const w = Math.min(440, Math.max(360, vw * 0.3)); |
| if (Math.abs(r.width - w) > 1) problems.push("width " + r.width + ", want " + w); |
| - if (Math.abs(r.height - h) > 1) problems.push("height " + r.height + ", want " + h); |
| - if (r.top < f.bottom + 4 || r.top > f.bottom + 24) problems.push("top " + r.top + ", the field ends at " + f.bottom); |
| - if (r.left < 12 - 0.5 || r.right > vw - 12 + 0.5 || r.bottom > vh) problems.push("at " + [r.left, r.top, r.right, r.bottom].join(",")); |
| - const p = getComputedStyle(d, "::before"); |
| - if (p.content === "none") return problems.concat("no pointer").join("; "); |
| - const px = r.left + parseFloat(p.left) + parseFloat(p.width) / 2; |
| - if (px < f.left || px > f.right) problems.push("pointer at " + px + ", the field is " + f.left + "-" + f.right); |
| - if (r.left + parseFloat(p.left) < r.left + 12 || r.left + parseFloat(p.left) + parseFloat(p.width) > r.right - 12) problems.push("the pointer is off the popover's edge"); |
| + if (Math.abs(r.top - (bar.bottom + 16)) > 1) problems.push("top " + r.top + ", the header ends at " + bar.bottom); |
| + if (Math.abs(r.bottom - (vh - 16)) > 1 || Math.abs(r.right - (vw - 16)) > 1) problems.push("ends at " + r.right + "," + r.bottom + " of " + vw + "," + vh); |
| + if (r.left < home.right - 0.5 || r.left < apps.right) problems.push("left " + r.left + ", Home ends at " + home.right + ", the apps at " + apps.right); |
| if (document.documentElement.scrollWidth > vw) problems.push("page overflows"); |
| return problems.join("; "); |
| })()` |
| -// openedJS is true once the panel is open and done moving. |
| -const openedJS = `(() => { const d = document.querySelector("#ask-panel"), s = getComputedStyle(d); |
| - return d.open && s.opacity === "1" && (s.transform === "none" || s.transform === "matrix(1, 0, 0, 1, 0, 0)"); })()` |
| - |
| -// On a wide screen the chat is a glass popover under the Ask field, not a |
| -// side panel; Escape or a click outside closes it, and focus goes back to |
| -// the field. |
| -func TestAskPopover(t *testing.T) { |
| +// On a wide screen the chat is docked beside Home, at every size; its |
| +// conversation passes AA in both themes. |
| +func TestAskDockLayout(t *testing.T) { |
| apps := teamApps(t) |
| rig, _, b := askBaseWith(t, func(c *config.Config) { c.OficinaApps = apps }) |
| installAll(t, b) |
| for _, size := range [][2]int64{{1280, 800}, {1024, 800}, {800, 800}, {700, 800}, {1280, 600}} { |
| when := fmt.Sprintf("%dx%d", size[0], size[1]) |
| - drive(t, rig, reducedMotion("dark", false), chromedp.EmulateViewport(size[0], size[1]), chromedp.Navigate(rig.Origin+"/"), |
| - chromedp.WaitVisible(chromedp.CSS("a.ask")), chromedp.Click(chromedp.CSS("a.ask")), |
| - chromedp.Poll[chromedp.Void](openedJS, chromedp.WithPollingTimeout(5*time.Second))) |
| - if got := harness.Evaluate[string](rig, popoverJS); got != "" { |
| + drive(t, rig, reducedMotion("dark", false), chromedp.EmulateViewport(size[0], size[1])) |
| + openPanel(t, rig) |
| + if got := harness.Evaluate[string](rig, dockedJS); got != "" { |
| t.Errorf("%s: %s", when, got) |
| } |
| - // A click outside closes it; focus goes back to the field. |
| - drive(t, rig, chromedp.MouseClickXY(30, float64(size[1])-30), |
| - chromedp.Poll[chromedp.Void](`!document.querySelector("#ask-panel").open`, chromedp.WithPollingTimeout(3*time.Second))) |
| - if got := harness.Evaluate[string](rig, `document.activeElement.className`); got != "ask" { |
| - t.Errorf("%s: after a click outside focus is on %q", when, got) |
| - } |
| } |
| - // Mid-conversation, in both themes. |
| + // Mid-conversation, in both themes; then closed. |
| for _, scheme := range []string{"dark", "light"} { |
| - drive(t, rig, reducedMotion(scheme, false), chromedp.EmulateViewport(1280, 800), chromedp.Navigate(rig.Origin+"/"), |
| - chromedp.WaitVisible(chromedp.CSS("a.ask")), chromedp.Click(chromedp.CSS("a.ask")), |
| - chromedp.Poll[chromedp.Void](openedJS, chromedp.WithPollingTimeout(5*time.Second))) |
| + drive(t, rig, reducedMotion(scheme, false), chromedp.EmulateViewport(1280, 800)) |
| + openPanel(t, rig) |
| if harness.Evaluate[int](rig, `document.querySelectorAll("#ask-panel .msg.coordinator").length`) == 0 { |
| drive(t, rig, chromedp.SendKeys(chromedp.CSS(`#ask-text`), "What can I do"), |
| chromedp.Click(chromedp.CSS(`#ask-panel form.composer button`)), |
| chromedp.Poll[chromedp.Void](`[...document.querySelectorAll("#ask-panel .msg.coordinator")].some(m => !m.classList.contains("draft"))`, |
| chromedp.WithPollingTimeout(10*time.Second))) |
| } |
| - if got := harness.Evaluate[string](rig, popoverJS); got != "" { |
| + if got := harness.Evaluate[string](rig, dockedJS); got != "" { |
| t.Errorf("%s, mid-conversation: %s", scheme, got) |
| } |
| - checkContrast(t, rig, "the popover, "+scheme, "#ask-panel .msg.person", "#ask-panel .msg.coordinator", "#ask-panel .ask-head h2") |
| + checkContrast(t, rig, "the docked chat, "+scheme, "#ask-panel .msg.person", "#ask-panel .msg.coordinator", "#ask-panel .ask-head h2") |
| layoutShot(t, rig, "desktop-chat-"+scheme) |
| - drive(t, rig, chromedp.KeyEvent("\u001b"), |
| - chromedp.Poll[chromedp.Void](`!document.querySelector("#ask-panel").open`, chromedp.WithPollingTimeout(3*time.Second))) |
| - if got := harness.Evaluate[string](rig, `document.activeElement.className`); got != "ask" { |
| - t.Errorf("%s: after Escape focus is on %q", scheme, got) |
| - } |
| + drive(t, rig, chromedp.Click(chromedp.CSS(`#ask-panel .ask-head button.close`)), |
| + chromedp.Poll[chromedp.Void](`!document.querySelector("#ask-panel").checkVisibility({ visibilityProperty: true })`, chromedp.WithPollingTimeout(3*time.Second))) |
| + askClosed(t, b, true) |
| + checkContrast(t, rig, "Home with the chat closed, "+scheme, ".ask-field span") |
| + layoutShot(t, rig, "desktop-home-closed-"+scheme) |
| + drive(t, rig, chromedp.Click(chromedp.CSS(".base-btn")), chromedp.Poll[chromedp.Void](settledJS, chromedp.WithPollingTimeout(3*time.Second))) |
| + askClosed(t, b, false) |
| } |
| drive(t, rig, reducedMotion("dark", false)) |
| } |
diff --git a/internal/browsertest/light_test.go b/internal/browsertest/light_test.go| index 6840438..8521731 100644 |
| --- a/internal/browsertest/light_test.go |
| +++ b/internal/browsertest/light_test.go |
| @@ -265,19 +265,22 @@ func TestLightMode(t *testing.T) { |
| } |
| drive(t, rig, prefersScheme("light")) |
| - // Light Home: the greeting, the lede, the steps, the Ask field and the |
| - // rail's labels. |
| - checkContrast(t, rig, "Home, light", ".hello", ".lede", ".team", ".steps li", "a.ask", ".app-grid .label") |
| + // Light Home with the chat closed: the greeting, the lede, the steps, |
| + // the Ask field and the apps' labels. |
| + drive(t, rig, chromedp.Click(chromedp.CSS(`#ask-panel .ask-head button.close`)), |
| + chromedp.Poll[chromedp.Void](`!document.querySelector("#ask-panel").checkVisibility({ visibilityProperty: true })`, chromedp.WithPollingTimeout(3*time.Second))) |
| + askClosed(t, b, true) |
| + checkContrast(t, rig, "Home, light", ".hello", ".lede", ".team", ".steps li", ".ask-field span", ".app-grid .label") |
| lightShot(t, rig, "home-desktop") |
| for _, tint := range []string{"teal", "violet", "mist", "amber", "rose"} { |
| iconContrast(t, rig, "Home, light", "nav.apps .tile.t-"+tint+" svg") |
| } |
| - for _, sel := range []string{"a.ask", "a.me", ".app-grid a.app", `.app-grid a.app[href="/store"]`} { |
| + for _, sel := range []string{".base-btn", "a.me", ".ask-field", ".app-grid a.app", `.app-grid a.app[href="/store"]`} { |
| focusRing(t, rig, "Home, light", sel) |
| } |
| - // The panel mid-conversation: both bubbles, the header and status. |
| - drive(t, rig, chromedp.Click(chromedp.CSS(`a.ask`)), chromedp.WaitVisible(chromedp.CSS(`#ask-panel textarea`)), |
| + // The docked chat mid-conversation: both bubbles, the header and status. |
| + drive(t, rig, chromedp.Click(chromedp.CSS(`.base-btn`)), chromedp.Poll[chromedp.Void](settledJS, chromedp.WithPollingTimeout(3*time.Second)), |
| chromedp.SendKeys(chromedp.CSS(`#ask-text`), "What can I do"), |
| chromedp.Click(chromedp.CSS(`#ask-panel form.composer button`)), |
| chromedp.Poll[chromedp.Void](`[...document.querySelectorAll("#ask-panel .msg.coordinator")].some(m => !m.classList.contains("draft"))`, |
| @@ -285,7 +288,6 @@ func TestLightMode(t *testing.T) { |
| chromedp.Poll[chromedp.Void](`getComputedStyle(document.querySelector("#ask-panel")).transform === "none"`, chromedp.WithPollingTimeout(3*time.Second))) |
| checkContrast(t, rig, "the panel, light", "#ask-panel .msg.person", "#ask-panel .msg.coordinator", "#ask-panel .ask-head h2") |
| lightShot(t, rig, "home-panel-open") |
| - drive(t, rig, chromedp.KeyEvent("\u001b")) |
| // Settings. |
| drive(t, rig, chromedp.EmulateViewport(1280, 800), chromedp.Navigate(rig.Origin+"/settings"), chromedp.WaitVisible(chromedp.CSS(`form.segmented`))) |
diff --git a/internal/browsertest/mobile_test.go b/internal/browsertest/mobile_test.go| index 204d89f..d6cbec1 100644 |
| --- a/internal/browsertest/mobile_test.go |
| +++ b/internal/browsertest/mobile_test.go |
| @@ -4,6 +4,7 @@ package browsertest |
| import ( |
| "context" |
| + "fmt" |
| "net/http" |
| "os" |
| "path/filepath" |
| @@ -58,7 +59,7 @@ func mobileShot(t *testing.T, rig *harness.Rig, name string) { |
| } |
| // Base on an iPhone-sized screen: every page fits 390px, Home's top bar |
| -// stays on one line, and the panel is a full-screen sheet whose composer |
| +// stays on one line, and the chat is a full-screen sheet whose composer |
| // stays on screen. |
| func TestMobile(t *testing.T) { |
| f := equipotest.New(t) |
| @@ -80,21 +81,21 @@ func TestMobile(t *testing.T) { |
| installAll(t, b) |
| signInByEmail(t, rig, rig.Origin, b.mail) |
| - // Home: on a phone the Ask field is a round icon button, on one line |
| - // with the wordmark and the avatar. |
| + // Home: on a phone the Base button sits on one line with the wordmark |
| + // and the avatar, and the Ask field is under the greeting. |
| noOverflow(t, rig, "Home") |
| if got := harness.Evaluate[string](rig, `(() => { |
| - const bar = document.querySelector(".topbar"), icon = document.querySelector("a.ask-icon"), field = document.querySelector("a.ask"); |
| - const shown = [...bar.children].filter(e => getComputedStyle(e).display !== "none"); |
| + const bar = document.querySelector(".topbar"), icon = document.querySelector("button.base-btn"), field = document.querySelector(".ask-field"); |
| + const shown = [...bar.querySelectorAll(":scope > *, :scope > form > *")].filter(e => getComputedStyle(e).display !== "none" && getComputedStyle(e).display !== "contents"); |
| const mids = shown.map(e => Math.round(e.getBoundingClientRect().top + e.getBoundingClientRect().height / 2)); |
| const problems = []; |
| if (Math.max(...mids) - Math.min(...mids) > 2) problems.push("top bar wraps: " + mids.join(",")); |
| - if (getComputedStyle(field).display !== "none") problems.push("the Ask field shows"); |
| - if (!icon || getComputedStyle(icon).display === "none") return problems.concat("no Ask icon").join("; "); |
| + if (!field.checkVisibility({ visibilityProperty: true })) problems.push("no Ask field under the greeting"); |
| + if (!icon || !icon.checkVisibility({ visibilityProperty: true })) return problems.concat("no Base button").join("; "); |
| const r = icon.getBoundingClientRect(), me = document.querySelector(".me").getBoundingClientRect(); |
| - if (Math.round(r.width) !== 44 || Math.round(r.height) !== 44) problems.push("icon is " + r.width + "x" + r.height); |
| + if (Math.round(r.width) !== 44 || Math.round(r.height) !== 44) problems.push("Base button is " + r.width + "x" + r.height); |
| if (Math.round(me.width) !== 44) problems.push("avatar is " + me.width); |
| - if (icon.getAttribute("aria-label") !== "Ask Base" || icon.getAttribute("href") !== "/ask") problems.push("icon label or link"); |
| + if (icon.getAttribute("aria-label") !== "Ask Base") problems.push("Base button labelled " + icon.getAttribute("aria-label")); |
| const used = shown.reduce((w, e) => w + e.getBoundingClientRect().width, 0); |
| if (bar.clientWidth - used < 60) problems.push("no room to spare: " + (bar.clientWidth - used)); |
| return problems.join("; "); |
| @@ -112,8 +113,8 @@ func TestMobile(t *testing.T) { |
| viewportShot(t, rig, "home-phone") |
| layoutShot(t, rig, "phone-home-dark") |
| - // The panel before connecting. |
| - drive(t, rig, chromedp.Click(chromedp.CSS(`a.ask-icon`)), |
| + // The chat before connecting. |
| + drive(t, rig, chromedp.Click(chromedp.CSS(`button.base-btn`)), |
| chromedp.WaitVisible(chromedp.CSS(`#ask-panel [data-when="connect"] button`)), |
| // The sheet slides up; click once it has arrived. |
| chromedp.Poll[chromedp.Void](`document.querySelector("#ask-panel").getBoundingClientRect().top === 0`, chromedp.WithPollingTimeout(3*time.Second))) |
| @@ -173,7 +174,7 @@ func TestMobile(t *testing.T) { |
| if (m.right > vw) problems.push("a message overflows"); |
| return problems.join("; "); |
| })()`); got != "" { |
| - t.Errorf("the panel on a phone: %s", got) |
| + t.Errorf("the chat on a phone: %s", got) |
| } |
| mobileShot(t, rig, "4-panel-conversation") |
| layoutShot(t, rig, "phone-chat-dark") |
| @@ -184,11 +185,11 @@ func TestMobile(t *testing.T) { |
| } |
| mobileShot(t, rig, "4c-panel-tight") |
| drive(t, rig, chromedp.KeyEvent("\u001b"), |
| - chromedp.Poll[chromedp.Void](`!document.querySelector("#ask-panel").open`, chromedp.WithPollingTimeout(3*time.Second))) |
| - // Focus goes back once the close event has run. |
| - drive(t, rig, chromedp.Poll[chromedp.Void](`document.activeElement.className === "ask-icon"`, chromedp.WithPollingTimeout(3*time.Second))) |
| - // Reopened from the icon, mid-conversation: the sheet slides up. |
| - drive(t, rig, chromedp.Click(chromedp.CSS(`a.ask-icon`)), chromedp.Sleep(90*time.Millisecond)) |
| + chromedp.Poll[chromedp.Void](phoneClosedJS, chromedp.WithPollingTimeout(3*time.Second))) |
| + // Focus goes back to the Base button, which opened it. |
| + drive(t, rig, chromedp.Poll[chromedp.Void](`document.activeElement.className === "base-btn"`, chromedp.WithPollingTimeout(3*time.Second))) |
| + // Reopened from the Base button, mid-conversation: the sheet slides up. |
| + drive(t, rig, chromedp.Click(chromedp.CSS(`button.base-btn`)), chromedp.Sleep(90*time.Millisecond)) |
| if top := harness.Evaluate[float64](rig, `document.querySelector("#ask-panel").getBoundingClientRect().top`); top <= 1 { |
| t.Errorf("the sheet did not slide up: at %v moments after opening", top) |
| } |
| @@ -204,8 +205,8 @@ func TestMobile(t *testing.T) { |
| drive(t, rig, chromedp.KeyEvent("\u001b")) |
| // With reduced motion there is no slide and no push-back: it just shows. |
| - drive(t, rig, reducedMotion("dark", true), chromedp.Poll[chromedp.Void](`!document.querySelector("#ask-panel").open`, chromedp.WithPollingTimeout(3*time.Second)), |
| - chromedp.Click(chromedp.CSS(`a.ask-icon`)), chromedp.Sleep(30*time.Millisecond)) |
| + drive(t, rig, reducedMotion("dark", true), chromedp.Poll[chromedp.Void](phoneClosedJS, chromedp.WithPollingTimeout(3*time.Second)), |
| + chromedp.Click(chromedp.CSS(`button.base-btn`)), chromedp.Sleep(30*time.Millisecond)) |
| if got := harness.Evaluate[string](rig, `(() => { const d = document.querySelector("#ask-panel").getBoundingClientRect(); |
| const h = getComputedStyle(document.querySelector("main.home")); |
| return d.top + " " + h.transform + " " + h.filter + " " + h.opacity; })()`); got != "0 none none 1" { |
| @@ -224,3 +225,54 @@ func TestMobile(t *testing.T) { |
| mobileShot(t, rig, p.name) |
| } |
| } |
| + |
| +// phoneClosedJS is true once the chat on a phone has gone: no phone-open, |
| +// out of sight. |
| +const phoneClosedJS = `!document.documentElement.classList.contains("phone-open") && !document.querySelector("#ask-panel").checkVisibility({ visibilityProperty: true })` |
| + |
| +// On a phone Home opens on the springboard with Ask Base out of sight, |
| +// whatever the member chose on a wide screen; the field brings it up full |
| +// screen over Home, which is out of reach behind it, and X or Escape closes |
| +// it. Neither is remembered. |
| +func TestAskPhoneUnchanged(t *testing.T) { |
| + rig, _, b := askBaseOn(t, nil, chromedp.EmulateViewport(390, 844, chromedp.EmulateMobile, chromedp.EmulateScale(3))) |
| + whole := `(() => { const r = document.querySelector("#ask-panel").getBoundingClientRect(); |
| + return [r.left, r.top, r.width, r.height].map(Math.round).join(" ") === "0 0 390 844" })()` |
| + for _, closed := range []bool{false, true} { |
| + if _, err := b.db.Exec(`UPDATE members SET ask_closed = ?`, closed); err != nil { |
| + t.Fatal(err) |
| + } |
| + when := fmt.Sprintf("ask_closed %v", closed) |
| + drive(t, rig, chromedp.Navigate(rig.Origin+"/"), chromedp.WaitVisible(chromedp.CSS(".ask-field"))) |
| + if got := harness.Evaluate[string](rig, `(() => { const problems = []; |
| + if (document.querySelector("#ask-panel").checkVisibility({ visibilityProperty: true })) problems.push("the chat shows"); |
| + if (!document.querySelector("#ask-panel").inert) problems.push("the chat is in reach"); |
| + if (document.querySelector("main.home").inert) problems.push("Home is out of reach"); |
| + const apps = document.querySelector("nav.apps").getBoundingClientRect(); |
| + if (apps.top > innerHeight || apps.width < 300) problems.push("no springboard: the apps at " + apps.top + ", " + apps.width + " wide"); |
| + return problems.join("; "); })()`); got != "" { |
| + t.Errorf("%s, Home: %s", when, got) |
| + } |
| + drive(t, rig, chromedp.Click(chromedp.CSS(".ask-field")), chromedp.Poll[chromedp.Void](whole, chromedp.WithPollingTimeout(3*time.Second))) |
| + if got := harness.Evaluate[string](rig, `[document.documentElement.classList.contains("phone-open"), document.activeElement.id, document.querySelector("main.home").inert, document.querySelector(".topbar").inert].join(" ")`); got != "true ask-text true true" { |
| + t.Errorf("%s, opened by the field: %q, want phone-open, focus in the composer, Home and the header out of reach", when, got) |
| + } |
| + if closed { |
| + mobileShot(t, rig, "9-chat-open-closed-on-desktop") |
| + } else { |
| + drive(t, rig, reducedMotion("light", false)) |
| + layoutShot(t, rig, "phone-chat-light") |
| + drive(t, rig, reducedMotion("dark", false)) |
| + } |
| + drive(t, rig, chromedp.Click(chromedp.CSS(`#ask-panel .ask-head button.close`)), chromedp.Poll[chromedp.Void](phoneClosedJS, chromedp.WithPollingTimeout(3*time.Second))) |
| + if got := harness.Evaluate[string](rig, `document.activeElement.className + " " + document.querySelector("main.home").inert`); got != "ask-field false" { |
| + t.Errorf("%s, after X: %q, want focus on the field and Home in reach", when, got) |
| + } |
| + drive(t, rig, chromedp.Click(chromedp.CSS(".ask-field")), chromedp.Poll[chromedp.Void](whole, chromedp.WithPollingTimeout(3*time.Second)), |
| + chromedp.KeyEvent("\u001b"), chromedp.Poll[chromedp.Void](phoneClosedJS, chromedp.WithPollingTimeout(3*time.Second))) |
| + var got bool |
| + if err := b.db.QueryRow(`SELECT ask_closed FROM members`).Scan(&got); err != nil || got != closed { |
| + t.Errorf("%s: a phone's open and close were kept: ask_closed %v %v", when, got, err) |
| + } |
| + } |
| +} |
diff --git a/internal/browsertest/scroll_test.go b/internal/browsertest/scroll_test.go| index 34cdf18..e950183 100644 |
| --- a/internal/browsertest/scroll_test.go |
| +++ b/internal/browsertest/scroll_test.go |
| @@ -31,7 +31,7 @@ const lastVisible = `(() => { |
| return out.join("; "); |
| })()` |
| -// The conversation follows its newest line in the popover and on a phone: |
| +// The conversation follows its newest line docked and on a phone: |
| // after sending it is at the bottom, with the last bubble wholly above the |
| // status row; streaming keeps it there; scrolled up, it stays put and |
| // offers Jump to latest. |
| @@ -39,7 +39,7 @@ func TestAskScrollFollowsNewest(t *testing.T) { |
| for _, size := range []struct { |
| name string |
| w, h int64 |
| - }{{"popover", 1280, 800}, {"phone", 390, 844}} { |
| + }{{"docked", 1280, 800}, {"phone", 390, 844}} { |
| t.Run(size.name, func(t *testing.T) { |
| var view chromedp.Action[chromedp.Void] |
| if size.name == "phone" { |
| @@ -53,8 +53,8 @@ func TestAskScrollFollowsNewest(t *testing.T) { |
| f.Say(fmt.Sprintf("Earlier line %d of a long conversation.", i)) |
| } |
| if size.name == "phone" { |
| - drive(t, rig, chromedp.Navigate(rig.Origin+"/"), chromedp.WaitVisible(chromedp.CSS(`a.ask-icon`)), |
| - chromedp.Click(chromedp.CSS(`a.ask-icon`)), chromedp.WaitVisible(chromedp.CSS(`#ask-panel textarea`))) |
| + drive(t, rig, chromedp.Navigate(rig.Origin+"/"), chromedp.WaitVisible(chromedp.CSS(`button.base-btn`)), |
| + chromedp.Click(chromedp.CSS(`button.base-btn`)), chromedp.WaitVisible(chromedp.CSS(`#ask-panel textarea`))) |
| } else { |
| openPanel(t, rig) |
| } |
diff --git a/internal/look/static/app.css b/internal/look/static/app.css| index d109e0d..d07232f 100644 |
| --- a/internal/look/static/app.css |
| +++ b/internal/look/static/app.css |
| @@ -297,12 +297,15 @@ button.alt[aria-busy="true"] { cursor: progress; } |
| .signin p.or { margin: 18px 0 10px; font-size: 14px; text-align: center; } |
| .signin p.addr { color: var(--frost); font-weight: 500; overflow-wrap: anywhere; } |
| -/* Home */ |
| -.home { padding: 18px 26px 28px; display: flex; flex-direction: column; } |
| +/* Home: the header across the top; under it Home on the left and, with |
| + Ask Base on, the chat docked on the right, full height. Home scrolls on |
| + its own; the chat keeps its place. */ |
| +.shell { --chat-w: clamp(360px, 30vw, 440px); --ease: cubic-bezier(.2,.8,.2,1); |
| + display: grid; grid-template-columns: minmax(0, 1fr) auto; grid-template-rows: auto minmax(0, 1fr); height: 100dvh; overflow: clip; } |
| +.shell > .topbar { grid-column: 1 / -1; margin: 16px 16px 0 24px; } |
| +.shell > .home { grid-column: 1; grid-row: 2; min-height: 0; overflow-y: auto; padding: 0 24px 28px; display: flex; flex-direction: column; } |
| .topbar { display: flex; align-items: center; gap: 16px; padding: 8px 10px 8px 16px; border-radius: 14px; } |
| -.team { font-size: 14px; color: var(--haze); } |
| -.ask { flex: 1; max-width: 420px; margin-left: auto; padding: 8px 14px; border-radius: 10px; font-size: 14px; color: var(--haze); |
| - background: var(--well); box-shadow: inset 0 0 0 1px var(--well-edge); display: flex; justify-content: space-between; } |
| +.team { font-size: 14px; color: var(--haze); margin-right: auto; } |
| .me { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; font-size: 12px; font-weight: 600; background: linear-gradient(140deg, var(--ember), var(--rose)); color: var(--ink); } |
| .hello { margin: 46px 0 0; font-size: clamp(34px, 4.4vw, 52px); font-weight: 500; letter-spacing: -0.035em; line-height: 1.05; } |
| .lede { margin: 12px 0 24px; color: var(--haze); font-size: 17px; } |
| @@ -322,6 +325,15 @@ button.alt[aria-busy="true"] { cursor: progress; } |
| .apps { width: fit-content; max-width: 100%; margin-top: 28px; padding: 20px 20px 14px; border-radius: 22px; } |
| .app-grid { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, 96px); max-width: calc(5 * 96px + 4 * 8px); |
| gap: 14px 8px; justify-items: center; } |
| +/* Beside the docked chat Home can be narrow: the grid takes four or three |
| + columns, so the panel still fits them, and where even three of 96px do |
| + not fit, three share the width. Base's own pages keep a row of three. */ |
| +.shell > .home { container: home / inline-size; } |
| +@media (min-width: 641px) { |
| + @container home (max-width: 553.98px) { .app-grid { grid-template-columns: repeat(4, 96px); } } |
| + @container home (max-width: 449.98px) { .app-grid { grid-template-columns: repeat(3, 96px); } } |
| + @container home (max-width: 345.98px) { .apps { width: auto; } .app-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } .app { width: 100%; min-width: 0; } } |
| +} |
| /* Base's own pages (Store, People, Settings) start a row of their own. */ |
| .app-grid > li:not(.own) + li.own { grid-column-start: 1; } |
| /* Each cell fills its column, so every app is the same width whatever its label. */ |
| @@ -400,7 +412,6 @@ a.app:hover { background: var(--hover); } |
| @media (prefers-reduced-motion: reduce) { |
| .fog, .fog i, .light, .light::after, .app.new, .app.leaving, .installing, .msg.draft::after { animation: none; } |
| - dialog.ask-panel { transition: none; } |
| .light { transform: skewX(-14deg); } |
| } |
| @@ -415,42 +426,40 @@ a.me { color: var(--ink); text-decoration: none; } |
| a.wordmark { color: inherit; text-decoration: none; min-height: 44px; border-radius: 8px; } |
| .notepad + form { margin-top: 16px; } |
| a.btn { display: inline-flex; align-items: center; text-decoration: none; } |
| -/* The Ask field: glass whether it is the link to the chat or, with the chat |
| - off, a disabled field (no native bevel, no greyed-out fill). */ |
| -.ask { appearance: none; border: 0; min-height: 36px; align-items: center; font: inherit; font-size: 14px; } |
| -.ask::placeholder { color: var(--haze); opacity: 1; } |
| -.ask:disabled { cursor: not-allowed; color: var(--haze); opacity: 1; } |
| -a.ask { text-decoration: none; transition: background .2s, box-shadow .2s; } |
| -a.ask:hover { background: var(--well-hover); box-shadow: inset 0 0 0 1px var(--accent-edge); } |
| -a.ask::after { content: "/"; color: var(--haze); opacity: .7; } |
| -/* The Ask icon stands in for the field on a phone. */ |
| -.ask-icon { display: none; flex: none; width: 44px; height: 44px; border-radius: 50%; place-items: center; margin-left: auto; color: var(--frost); |
| - background: var(--well); box-shadow: inset 0 0 0 1px var(--well-ring); transition: background .2s, box-shadow .2s; } |
| -.ask-icon:hover { background: var(--well-hover); box-shadow: inset 0 0 0 1px var(--accent-edge); } |
| -.ask-icon svg { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; } |
| -.ask-icon svg path + path { stroke-width: 2.4; } |
| +/* The Base button in the header opens Ask Base; on a wide screen it shows |
| + only while the chat is closed. Its mark is the wordmark's. */ |
| +.base-btn-form, .dock-close { display: contents; } |
| +.base-btn { flex: none; width: 44px; height: 44px; padding: 0; border: 0; border-radius: 50%; display: grid; place-items: center; cursor: pointer; |
| + background: var(--well); box-shadow: inset 0 0 0 1px var(--well-ring); overflow: hidden; |
| + transition: background .2s, box-shadow .2s, opacity .3s, transform .45s var(--ease), width 0s, visibility 0s; } |
| +.base-btn:hover { background: var(--well-hover); box-shadow: inset 0 0 0 1px var(--accent-edge); } |
| +.base-btn .mark, .ask-head .mark { flex: none; width: 14px; height: 14px; border-radius: 4px; |
| + background: linear-gradient(160deg, var(--mark-1), var(--mark-2)); box-shadow: inset 0 0 0 1px var(--mark-edge); } |
| +.base-btn .mark { width: 18px; height: 18px; border-radius: 5px; } |
| +/* The Ask field under the greeting, with its "/" hint. It folds away |
| + while the chat is docked open (see the wide-screen rules). */ |
| +.ask-slot { display: grid; grid-template-rows: 1fr; transition: opacity .3s .1s, transform .45s var(--ease), visibility 0s; } |
| +.ask-slot > div { min-height: 0; overflow: hidden; margin: 0 -3px; } |
| +.ask-field-form { padding: 0 3px 22px; } |
| +.ask-field { width: 100%; max-width: 520px; height: 48px; padding: 0 16px; border: 0; border-radius: 12px; display: flex; align-items: center; gap: 12px; |
| + cursor: text; text-align: left; font: inherit; font-size: 15px; color: var(--haze); background: var(--well); box-shadow: inset 0 0 0 1px var(--well-edge); |
| + transition: background .2s, box-shadow .2s; } |
| +.ask-field:hover { background: var(--well-hover); box-shadow: inset 0 0 0 1px var(--accent-edge); } |
| +.ask-field span { flex: 1; } |
| +.ask-field kbd { font: inherit; font-size: 13px; opacity: .75; } |
| .sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; } |
| -/* Ask Base. On a wide screen, a glass popover under the Ask field, its |
| - pointer toward it (ask.js places it: --pop-top, --pop-left, --pointer-x); |
| - on a phone, a sheet that slides up over Home, which steps back behind it |
| - (see the phone rules). The same conversation is the /ask page. */ |
| -dialog.ask-panel { position: fixed; inset: auto; top: var(--pop-top, 76px); left: var(--pop-left, auto); right: var(--pop-right, 26px); |
| - width: min(440px, calc(100vw - 24px)); height: min(640px, calc(100dvh - 120px)); |
| - max-width: none; max-height: none; margin: 0; padding: 0; border-radius: 18px; color: var(--frost); |
| - background: linear-gradient(var(--sheet-1), var(--sheet-2)), var(--sheet-base); |
| - flex-direction: column; overflow: visible; transform-origin: var(--pointer-x, 50%) 0; |
| - transition: transform .25s cubic-bezier(.2,.7,0,1), opacity .25s, overlay .25s allow-discrete, display .25s allow-discrete; |
| - transform: translateY(-8px) scale(.98); opacity: 0; } |
| -dialog.ask-panel::before { content: ""; position: absolute; top: -8px; left: var(--pointer-x, calc(50% - 7px)); width: 14px; height: 14px; |
| - transform: rotate(45deg); border-radius: 3px 0 0 0; |
| - background: linear-gradient(var(--sheet-1), var(--sheet-1)), var(--sheet-base); |
| - border-left: 1px solid var(--glass-edge); border-top: 1px solid var(--glass-edge); } |
| -dialog.ask-panel[open] { display: flex; transform: none; opacity: 1; } |
| -@starting-style { dialog.ask-panel[open] { transform: translateY(-8px) scale(.98); opacity: 0; } } |
| -dialog.ask-panel::backdrop { background: transparent; } |
| +/* Ask Base on Home: docked on the right under the header, full height, in |
| + its own glass. Its column takes its width at once when it opens and |
| + gives it back once the chat has slid away: only transform and opacity |
| + move. On a phone, a full-screen sheet over Home (see the phone rules). |
| + The same conversation is the /ask page. */ |
| +.chat-col { grid-column: 2; grid-row: 2; position: relative; width: calc(var(--chat-w) + 16px); } |
| +aside.ask-panel { position: absolute; top: 16px; right: 16px; bottom: 16px; width: var(--chat-w); display: flex; flex-direction: column; overflow: hidden; |
| + border-radius: 20px; color: var(--frost); background: linear-gradient(var(--sheet-1), var(--sheet-2)), var(--sheet-base); |
| + transition: transform .45s var(--ease), opacity .3s, visibility 0s; } |
| .ask-head { display: flex; align-items: center; gap: 8px; padding: 14px 14px 12px 20px; border-bottom: 1px solid var(--rule); } |
| -.ask-head h2 { flex: 1; margin: 0; font-size: 20px; font-weight: 500; letter-spacing: -0.02em; font-variation-settings: "STYL" 0; } |
| +.ask-head h2 { flex: 1; display: flex; align-items: center; gap: 10px; margin: 0; font-size: 20px; font-weight: 500; letter-spacing: -0.02em; font-variation-settings: "STYL" 0; } |
| /* The header's round glass button: close. */ |
| .ask-head .round { flex: none; width: 44px; height: 44px; padding: 0; border: 0; border-radius: 50%; display: grid; place-items: center; cursor: pointer; |
| color: var(--frost); background: var(--chip); box-shadow: inset 0 0 0 1px var(--chip-edge); transition: background .2s, box-shadow .2s; } |
| @@ -508,28 +517,43 @@ dialog.ask-panel::backdrop { background: transparent; } |
| .ask-page { height: calc(100dvh - 36px); min-height: 420px; } |
| .signin p.code { margin: 6px 0 18px; font-size: 32px; font-weight: 600; letter-spacing: .14em; text-align: center; color: var(--frost); |
| font-variant-numeric: tabular-nums; font-variation-settings: "STYL" 0; } |
| -body:has(dialog.ask-panel[open]) { overflow: hidden; } |
| main { min-height: 100dvh; } |
| -/* Phones. The top bar keeps to one line: no team name, no "/" hint, the |
| - Ask field truncates rather than wraps. The panel is a full-screen sheet |
| - sized to the visual viewport (ask.js sets --vv-h and --vv-top while it |
| - is open, so the composer stays above the keyboard), with the header at |
| +/* Wide screens: open, the chat is docked and the greeting's field and the |
| + Base button fold away; closing it (desk-closed) slides it out to the |
| + right, Home takes the width, and they come back. */ |
| +@media (min-width: 641px) { |
| + html:not(.desk-closed) .base-btn { width: 0; opacity: 0; transform: scale(.6); visibility: hidden; pointer-events: none; |
| + transition: opacity .2s, transform .45s var(--ease), width 0s .45s, visibility 0s .45s; } |
| + html:not(.desk-closed) .ask-slot { grid-template-rows: 0fr; opacity: 0; transform: translateY(-6px); visibility: hidden; |
| + transition: opacity .2s, transform .2s var(--ease), grid-template-rows 0s .2s, visibility 0s .2s; } |
| + .desk-closed .chat-col { width: 0; transition: width 0s .45s; } |
| + .desk-closed aside.ask-panel { transform: translateX(calc(100% + 32px)); opacity: 0; visibility: hidden; |
| + transition: transform .45s var(--ease), opacity .3s .1s, visibility 0s .45s; } |
| +} |
| + |
| +/* Phones: Home is the springboard first, and the page scrolls. The top bar |
| + keeps to one line: no team name, the Base button beside the avatar. The |
| + field or the Base button brings the chat up full screen over Home |
| + (phone-open), sized to the visual viewport (ask.js sets --vv-h and |
| + --vv-top, so the composer stays above the keyboard), with the header at |
| the top, the conversation scrolling between, and room for the notch and |
| - the home indicator. */ |
| -@media (max-width: 600px) { |
| - .home { padding: 12px 12px calc(20px + env(safe-area-inset-bottom)); } |
| + the home indicator. Home steps back behind it. */ |
| +@media (max-width: 640px) { |
| + .shell { display: block; height: auto; min-height: 100dvh; overflow: visible; } |
| + .shell > .topbar { margin: 12px 12px 0; transform-origin: 50% 0; transition: transform .4s var(--ease), filter .4s; } |
| + .shell > .home { overflow: visible; padding: 0 12px calc(20px + env(safe-area-inset-bottom)); transform-origin: 50% 30%; transition: transform .4s var(--ease), filter .4s; } |
| .topbar { gap: 10px; padding: 6px 6px 6px 12px; } |
| .team { display: none; } |
| - .ask { min-width: 0; min-height: 44px; max-width: none; padding: 0 14px; } |
| - a.ask { display: none; } |
| - .ask-icon { display: grid; } |
| - .ask, a.ask { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; } |
| + .topbar .wordmark { margin-right: auto; } |
| .me, .topbar a.me { flex: none; width: 44px; height: 44px; margin: 0; padding: 0; font-size: 14px; } |
| /* A springboard: a compact greeting, then four columns of apps in the |
| glass panel, at iOS-like spacing. It scrolls with Home. */ |
| .hello { margin-top: 26px; font-size: 30px; } |
| .lede { margin: 8px 0 14px; font-size: 15px; } |
| + .ask-field-form { padding-bottom: 14px; } |
| + .ask-field { max-width: none; height: 44px; } |
| + .ask-field kbd { display: none; } |
| .steps { gap: 6px; } |
| .steps li { padding: 6px 10px; font-size: 13px; gap: 8px; } |
| .apps { margin-top: 22px; padding: 16px 6px 12px; max-width: none; border-radius: 26px; } |
| @@ -537,41 +561,42 @@ main { min-height: 100dvh; } |
| .app-grid { grid-template-columns: repeat(4, 1fr); max-width: none; gap: 16px 0; } |
| .app { width: 100%; max-width: 86px; padding: 4px 2px 2px; gap: 6px; font-size: 12px; } |
| .app .icon { width: 60px; height: 60px; } |
| - /* Opening the chat, Home steps back behind the sheet. */ |
| - main.home { transform-origin: 50% 30%; transition: transform .4s cubic-bezier(.2,.8,.2,1), filter .4s; } |
| - body:has(dialog.ask-panel[open]) main.home { transform: scale(.94); filter: blur(3px) brightness(.8); } |
| + .chat-col { position: fixed; inset: 0; z-index: 20; width: auto; pointer-events: none; } |
| + aside.ask-panel { top: var(--vv-top, 0); right: 0; bottom: auto; left: 0; width: auto; height: var(--vv-h, 100dvh); |
| + border: 0; border-radius: 0; padding: 0 env(safe-area-inset-right) 0 env(safe-area-inset-left); box-shadow: none; |
| + transform: translateY(100%); visibility: hidden; transition: transform .4s var(--ease), visibility 0s .4s; } |
| + .phone-open .chat-col { pointer-events: auto; } |
| + .phone-open aside.ask-panel { transform: none; visibility: visible; transition: transform .4s var(--ease), visibility 0s; } |
| + .phone-open .shell > .home, .phone-open .shell > .topbar { transform: scale(.94); filter: blur(3px) brightness(.8); } |
| + html.phone-open body { overflow: hidden; } |
| + aside.ask-panel .ask-head { padding: max(8px, env(safe-area-inset-top)) 12px 8px 16px; } |
| + aside.ask-panel .ask-head h2 { font-size: 18px; } |
| + aside.ask-panel .composer { padding: 8px 8px calc(8px + env(safe-area-inset-bottom)); } |
| + aside.ask-panel .ask-foot { padding: 0 8px; } |
| + aside.ask-panel .ask-empty, aside.ask-panel .ask-problem { padding: 0 12px 12px; } |
| + aside.ask-panel .thread { padding: 14px 12px; } |
| + aside.ask-panel .msg { max-width: 92%; } |
| +} |
| + |
| +/* Phones, beyond Home: the inner pages and /ask. */ |
| +@media (max-width: 600px) { |
| .inner { padding: 10px; } |
| .sheet { padding: 18px 16px 20px; } |
| .people li { flex-wrap: wrap; } |
| - dialog.ask-panel { inset: auto 0 auto 0; top: var(--vv-top, 0); width: 100%; height: var(--vv-h, 100dvh); max-height: var(--vv-h, 100dvh); |
| - border: 0; border-radius: 0; padding: 0 env(safe-area-inset-right) 0 env(safe-area-inset-left); |
| - overflow: hidden; opacity: 1; transform: none; transition: none; } |
| - dialog.ask-panel::before { display: none; } |
| - /* The sheet slides up each time it opens. */ |
| - dialog.ask-panel[open] { animation: sheet-up .4s cubic-bezier(.2,.8,.2,1); } |
| - @starting-style { dialog.ask-panel[open] { transform: none; opacity: 1; } } |
| - dialog.ask-panel::backdrop { background: var(--scrim); } |
| - dialog.ask-panel .ask-head { position: sticky; top: 0; z-index: 1; padding: max(8px, env(safe-area-inset-top)) 12px 8px; } |
| - dialog.ask-panel .ask-head h2 { font-size: 18px; } |
| - dialog.ask-panel .composer { padding: 8px 8px calc(8px + env(safe-area-inset-bottom)); } |
| - dialog.ask-panel .ask-foot { padding: 0 8px; } |
| - dialog.ask-panel .ask-empty, dialog.ask-panel .ask-problem { padding: 0 12px 12px; } |
| .thread { padding: 14px 12px; } |
| .msg { max-width: 92%; } |
| .ask-page { height: calc(100dvh - 20px); } |
| } |
| -/* With reduced motion the chat just shows: no slide, no scale, and Home |
| - does not step back, blur or dim behind it. Send and Stop just appear. */ |
| +/* With reduced motion the chat just shows and goes: no slide, no fade, the |
| + field and the Base button fold at once, and on a phone Home does not |
| + step back, blur or dim behind it. Send and Stop just appear. */ |
| @media (prefers-reduced-motion: reduce) { |
| - dialog.ask-panel, dialog.ask-panel[open], main.home { transition: none; transform: none; animation: none; } |
| - @starting-style { dialog.ask-panel[open] { transform: none; opacity: 1; } } |
| - body:has(dialog.ask-panel[open]) main.home { transform: none; filter: none; opacity: 1; } |
| + .base-btn, .ask-slot, .chat-col, aside.ask-panel, .shell > .home, .shell > .topbar { transition: none !important; } |
| + .phone-open .shell > .home, .phone-open .shell > .topbar { transform: none; filter: none; } |
| .composer .actions button { animation: none; } |
| } |
| -@keyframes sheet-up { from { transform: translateY(100%); } } |
| - |
| /* Scratchpad's shared note: a field that grows past one control height. */ |
| .notepad { display: flex; flex-direction: column; gap: 12px; align-items: flex-start; } |
| .notepad textarea.input { font: inherit; width: 100%; height: auto; min-height: 280px; padding: 12px 14px; |
diff --git a/internal/look/static/ask.js b/internal/look/static/ask.js| index a8620ef..009598f 100644 |
| --- a/internal/look/static/ask.js |
| +++ b/internal/look/static/ask.js |
| @@ -1,16 +1,16 @@ |
| -// "Ask Base anything": the chat panel over Home (a <dialog>), and the /ask |
| -// page. Without this script the field is a link to /ask, whose forms post |
| -// and come back; with it, the same forms go by fetch and replies stream in |
| -// through /ask/events, which Base relays from Equipo. Text is only ever set |
| -// with textContent. |
| +// "Ask Base anything": the chat docked beside Home (an <aside>), and the |
| +// /ask page. Without this script the chat's forms post and come back (on |
| +// Home, the X and the Base button post to /ask/dock); with it, the same |
| +// forms go by fetch and replies stream in through /ask/events, which Base |
| +// relays from Equipo. Text is only ever set with textContent. |
| const root = document.querySelector("[data-ask]"); |
| if (root) start(root); |
| function start(root) { |
| - const dialog = root.tagName === "DIALOG" ? root : null; |
| - // The Ask field, and on a phone the round Ask icon: whichever opened the |
| - // panel gets focus back when it closes. |
| + const dock = root.tagName === "ASIDE" ? root : null; |
| + // The Base button and the Ask field under the greeting: whichever opened |
| + // the chat on a phone gets focus back when it closes. |
| const openers = document.querySelectorAll("[data-ask-open]"); |
| let opener = openers[0]; |
| const thread = root.querySelector(".thread"); |
| @@ -282,7 +282,7 @@ function start(root) { |
| source = null; |
| } |
| - const live = () => !dialog || dialog.open; |
| + const live = () => !dock || isOpen(); |
| async function load() { |
| let s; |
| @@ -409,74 +409,113 @@ function start(root) { |
| if (out.turn) setTurn(out.turn); |
| }); |
| - if (!dialog) { |
| + if (!dock) { |
| load(); |
| return; |
| } |
| - // On a phone the sheet follows the visual viewport, which shrinks when the |
| - // keyboard opens: the composer stays above it. |
| - const vv = window.visualViewport; |
| - function fit() { |
| - if (!vv) return; |
| - dialog.style.setProperty("--vv-h", vv.height + "px"); |
| - dialog.style.setProperty("--vv-top", vv.offsetTop + "px"); |
| + |
| + // Docked beside Home. A wide screen opens with the chat docked, unless the |
| + // member closed it there (<html class="desk-closed">, drawn by the server |
| + // and kept by /ask/dock); a phone opens on the springboard, and the chat |
| + // comes up full screen over it (phone-open), not remembered. Each keeps |
| + // its own state, so crossing 640px never strands the chat. |
| + const html = document.documentElement; |
| + const phone = matchMedia("(max-width: 640px)"); |
| + const home = document.getElementById("home"); |
| + const bar = document.querySelector(".shell > .topbar"); |
| + const slot = document.querySelector(".ask-slot"); |
| + function isOpen() { |
| + return phone.matches ? html.classList.contains("phone-open") : !html.classList.contains("desk-closed"); |
| } |
| - if (vv) { |
| - vv.addEventListener("resize", () => { if (dialog.open) fit(); }); |
| - vv.addEventListener("scroll", () => { if (dialog.open) fit(); }); |
| + // What is out of sight is out of reach: the chat while closed, the |
| + // greeting's field while docked open, and Home behind the chat on a phone. |
| + // The conversation is read afresh and followed while the chat is open. |
| + let shown = false; |
| + function sync() { |
| + const open = isOpen(); |
| + dock.inert = !open; |
| + if (slot) slot.inert = open && !phone.matches; |
| + if (home) home.inert = open && phone.matches; |
| + if (bar) bar.inert = open && phone.matches; |
| + for (const o of openers) o.setAttribute("aria-expanded", String(open)); |
| + if (open !== shown) { |
| + shown = open; |
| + if (open) load(); |
| + else quiet(); |
| + } |
| } |
| - |
| - // On a wide screen the panel is a popover under the Ask field, centred on |
| - // it as far as the screen allows, its pointer over the field's middle. |
| - // On a phone the CSS makes it a full-screen sheet and ignores these. |
| - const wide = matchMedia("(min-width: 601px)"); |
| - const askField = document.querySelector("a.ask"); |
| - function place() { |
| - if (!wide.matches || !askField) return; |
| - const f = askField.getBoundingClientRect(); |
| - const vw = document.documentElement.clientWidth; |
| - const w = Math.min(440, vw - 24); |
| - const left = Math.max(12, Math.min(f.left + f.width / 2 - w / 2, vw - 12 - w)); |
| - const pointer = Math.max(20, Math.min(f.left + f.width / 2 - left, w - 20)); |
| - dialog.style.setProperty("--pop-top", f.bottom + 12 + "px"); |
| - dialog.style.setProperty("--pop-left", left + "px"); |
| - dialog.style.setProperty("--pop-right", "auto"); |
| - dialog.style.setProperty("--pointer-x", pointer - 7 + "px"); |
| + // The first thing to reach in the chat: the composer, or the visible |
| + // note's button. |
| + function first() { |
| + return chatting(root.dataset.state) ? field : root.querySelector("[data-when]:not([hidden]) .btn"); |
| } |
| - window.addEventListener("resize", () => { if (dialog.open) place(); }); |
| - |
| - function open() { |
| - if (dialog.open) return; |
| - fit(); |
| - place(); |
| - dialog.showModal(); |
| - load().then(() => { |
| - const first = chatting(root.dataset.state) ? field : dialog.querySelector("[data-when]:not([hidden]) .btn"); |
| - if (first) first.focus(); |
| - }); |
| - field.focus(); |
| + function setOpen(open) { |
| + if (phone.matches) { |
| + html.classList.toggle("phone-open", open); |
| + if (open) fit(); |
| + } else { |
| + html.classList.toggle("desk-closed", !open); |
| + // Kept for the member's next visit; the class has already moved. |
| + fetch("/ask/dock", { method: "POST", headers: json, body: new URLSearchParams({ open: open ? "1" : "0" }) }).catch(() => {}); |
| + } |
| + sync(); |
| + if (open) { |
| + const f = first(); |
| + if (f) f.focus({ preventScroll: true }); |
| + return; |
| + } |
| + // Focus goes back to whichever opener shows: on a wide screen the Base |
| + // button, which appears as the chat leaves. |
| + const back = phone.matches && opener.checkVisibility() ? opener : [...openers].find((o) => o.checkVisibility({ visibilityProperty: true })) || openers[0]; |
| + if (back) back.focus({ preventScroll: true }); |
| } |
| - for (const o of openers) { |
| - o.addEventListener("click", (e) => { |
| + for (const form of document.querySelectorAll('form[action="/ask/dock"]')) { |
| + form.addEventListener("submit", (e) => { |
| e.preventDefault(); |
| - opener = o; |
| - open(); |
| + const open = form.elements.open.value === "1"; |
| + if (open) opener = e.submitter || form.querySelector("button"); |
| + setOpen(open); |
| }); |
| } |
| - dialog.querySelector("[data-ask-close]").addEventListener("click", () => dialog.close()); |
| - // A click outside the panel (on its backdrop) closes it too. |
| - dialog.addEventListener("click", (e) => { |
| - if (e.target === dialog) dialog.close(); |
| - }); |
| - dialog.addEventListener("close", () => { |
| - quiet(); |
| - opener.focus(); |
| + document.addEventListener("keydown", (e) => { |
| + if (e.defaultPrevented || e.ctrlKey || e.metaKey || e.altKey) return; |
| + const el = document.activeElement; |
| + if (e.key === "Escape" && isOpen() && dock.contains(el)) { |
| + setOpen(false); |
| + return; |
| + } |
| + // "/" reaches the chat from anywhere but a field: it opens it, or |
| + // puts focus in the composer. |
| + const typing = el && (el.isContentEditable || /^(INPUT|TEXTAREA|SELECT)$/.test(el.tagName)); |
| + if (e.key !== "/" || typing) return; |
| + e.preventDefault(); |
| + if (!isOpen()) { |
| + opener = [...openers].find((o) => o.checkVisibility({ visibilityProperty: true })) || openers[0]; |
| + setOpen(true); |
| + return; |
| + } |
| + const f = first(); |
| + if (f) f.focus({ preventScroll: true }); |
| }); |
| + phone.addEventListener("change", sync); |
| + |
| + // On a phone the chat follows the visual viewport, which shrinks when the |
| + // keyboard opens: the composer stays above it. |
| + const vv = window.visualViewport; |
| + function fit() { |
| + if (!vv) return; |
| + dock.style.setProperty("--vv-h", vv.height + "px"); |
| + dock.style.setProperty("--vv-top", vv.offsetTop + "px"); |
| + } |
| + if (vv) { |
| + vv.addEventListener("resize", () => { if (phone.matches && isOpen()) fit(); }); |
| + vv.addEventListener("scroll", () => { if (phone.matches && isOpen()) fit(); }); |
| + } |
| + |
| + // Back from setting up Ask Base on Home (/#ask): the chat open. |
| if (location.hash === "#ask") { |
| history.replaceState(null, "", location.pathname + location.search); |
| - // Opened by the address, not a click: focus goes back to whichever |
| - // opener this screen shows (the icon on a phone). |
| - opener = [...openers].find((o) => o.getClientRects().length > 0) || opener; |
| - open(); |
| + if (!isOpen()) setOpen(true); |
| } |
| + sync(); |
| } |
diff --git a/internal/look/templates/layout.html b/internal/look/templates/layout.html| index c310e9a..89a6df5 100644 |
| --- a/internal/look/templates/layout.html |
| +++ b/internal/look/templates/layout.html |
| @@ -1,5 +1,5 @@ |
| -{{define "layout"}}<!DOCTYPE html> |
| -<html lang="en"{{with theme}} data-theme="{{.}}"{{end}}> |
| +{{define "layout"}}<!DOCTYPE html>{{/* A page's "root" block adds to <html>: Home's class="desk-closed". */}} |
| +<html lang="en"{{with theme}} data-theme="{{.}}"{{end}}{{block "root" .}}{{end}}> |
| <head> |
| <meta charset="utf-8"> |
| <meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover, interactive-widget=resizes-content"> |
diff --git a/internal/store/askdock.go b/internal/store/askdock.go| new file mode 100644 |
| index 0000000..89af6e1 |
| --- /dev/null |
| +++ b/internal/store/askdock.go |
| @@ -0,0 +1,22 @@ |
| +package store |
| + |
| +import ( |
| + "context" |
| + "database/sql" |
| + "fmt" |
| +) |
| + |
| +// SetAskClosed keeps whether the member has closed Ask Base, docked beside |
| +// Home on a wide screen: closed until they open it again, on every device. |
| +func SetAskClosed(ctx context.Context, db *sql.DB, memberID string, closed bool) error { |
| + res, err := db.ExecContext(ctx, `UPDATE members SET ask_closed = ? WHERE id = ?`, closed, memberID) |
| + if err != nil { |
| + return err |
| + } |
| + if n, err := res.RowsAffected(); err != nil { |
| + return err |
| + } else if n != 1 { |
| + return fmt.Errorf("store: no member %s", memberID) |
| + } |
| + return nil |
| +} |
diff --git a/internal/store/askdock_test.go b/internal/store/askdock_test.go| new file mode 100644 |
| index 0000000..d26473f |
| --- /dev/null |
| +++ b/internal/store/askdock_test.go |
| @@ -0,0 +1,58 @@ |
| +package store |
| + |
| +import ( |
| + "context" |
| + "testing" |
| +) |
| + |
| +// Ask Base starts docked open for every member; a close is the member's |
| +// own, kept on their row, and opening it again clears it. |
| +func TestAskClosedRoundTrip(t *testing.T) { |
| + ctx, db := context.Background(), open(t) |
| + ana, _, err := Invite(ctx, db, "ana@example.com") |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + bo, _, err := Invite(ctx, db, "bo@example.com") |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + closed := func(email string) bool { |
| + t.Helper() |
| + m, ok, err := MemberByEmail(ctx, db, email) |
| + if err != nil || !ok { |
| + t.Fatalf("%s: %v %v", email, ok, err) |
| + } |
| + return m.AskClosed |
| + } |
| + if closed("ana@example.com") || closed("bo@example.com") { |
| + t.Fatal("a fresh member starts with Ask Base closed") |
| + } |
| + if err := SetAskClosed(ctx, db, ana.ID, true); err != nil { |
| + t.Fatal(err) |
| + } |
| + if !closed("ana@example.com") { |
| + t.Error("closed, it reads back open") |
| + } |
| + if closed("bo@example.com") { |
| + t.Error("closing it for one member closed it for another") |
| + } |
| + ms, err := Members(ctx, db) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + for _, m := range ms { |
| + if m.AskClosed != (m.ID == ana.ID) { |
| + t.Errorf("Members: %s reads closed=%v", m.Email, m.AskClosed) |
| + } |
| + } |
| + if err := SetAskClosed(ctx, db, ana.ID, false); err != nil { |
| + t.Fatal(err) |
| + } |
| + if closed("ana@example.com") { |
| + t.Error("opened again, it reads back closed") |
| + } |
| + if err := SetAskClosed(ctx, db, bo.ID+"x", true); err == nil { |
| + t.Error("set for a member who isn't there") |
| + } |
| +} |
diff --git a/internal/store/members.go b/internal/store/members.go| index 3541aa1..3249d4e 100644 |
| --- a/internal/store/members.go |
| +++ b/internal/store/members.go |
| @@ -21,9 +21,12 @@ type Member struct { |
| // Theme is the member's Appearance: "" follows the device; "light" or |
| // "dark" holds that one on every device. |
| Theme string |
| + // AskClosed is true once the member has closed Ask Base, docked open |
| + // beside Home on a wide screen, until they open it again. |
| + AskClosed bool |
| } |
| -const memberCols = `id, email, name, role, invited_at, joined_at, invite_sent_at, theme` |
| +const memberCols = `id, email, name, role, invited_at, joined_at, invite_sent_at, theme, ask_closed` |
| // memberColsOf is memberCols qualified by a table alias, for joins. |
| func memberColsOf(alias string) string { |
| @@ -39,7 +42,7 @@ type scanner interface{ Scan(...any) error } |
| func scanMember(s scanner) (Member, error) { |
| var m Member |
| var joined, sent sql.NullTime |
| - if err := s.Scan(&m.ID, &m.Email, &m.Name, &m.Role, &m.InvitedAt, &joined, &sent, &m.Theme); err != nil { |
| + if err := s.Scan(&m.ID, &m.Email, &m.Name, &m.Role, &m.InvitedAt, &joined, &sent, &m.Theme, &m.AskClosed); err != nil { |
| return Member{}, err |
| } |
| if joined.Valid { |
diff --git a/internal/store/migrations/0011_ask_closed.sql b/internal/store/migrations/0011_ask_closed.sql| new file mode 100644 |
| index 0000000..bae4135 |
| --- /dev/null |
| +++ b/internal/store/migrations/0011_ask_closed.sql |
| @@ -0,0 +1,3 @@ |
| +-- ask_closed: Ask Base closed by the member on a wide screen, where it is |
| +-- docked open beside Home by default. Theirs, on every device. |
| +ALTER TABLE members ADD COLUMN ask_closed integer NOT NULL DEFAULT 0; |
diff --git a/internal/web/ask.go b/internal/web/ask.go| index 62d4967..fcb3f3b 100644 |
| --- a/internal/web/ask.go |
| +++ b/internal/web/ask.go |
| @@ -40,6 +40,34 @@ func (a *app) askRoutes(r chi.Router) { |
| r.Get("/ask/connect", a.askConnectPage) |
| r.Post("/ask/connect/check", a.askConnectCheck) |
| r.Post("/ask/disconnect", a.askDisconnect) |
| + r.Post("/ask/dock", a.askDock) |
| +} |
| + |
| +// askDock is POST /ask/dock: on a wide screen the X closes Ask Base, docked |
| +// beside Home (open=0), and the Base button or the field opens it again |
| +// (open=1), kept for the member on every device. Plain forms, so they work |
| +// without scripts; the script posts them by fetch and gets a 204. |
| +func (a *app) askDock(w http.ResponseWriter, r *http.Request) { |
| + me, _ := CurrentMember(r) |
| + var closed bool |
| + switch r.PostFormValue("open") { |
| + case "1": |
| + case "0": |
| + closed = true |
| + default: |
| + http.Error(w, "bad request", http.StatusBadRequest) |
| + return |
| + } |
| + if err := store.SetAskClosed(r.Context(), a.db, me.ID, closed); err != nil { |
| + a.logger.Error("ask: dock", "err", err) |
| + http.Error(w, "unavailable", http.StatusServiceUnavailable) |
| + return |
| + } |
| + if wantsJSON(r) { |
| + w.WriteHeader(http.StatusNoContent) |
| + return |
| + } |
| + http.Redirect(w, r, "/", http.StatusSeeOther) |
| } |
| func newAsker(origin, instanceKey, name string) *asker { |
diff --git a/internal/web/home.go b/internal/web/home.go| index cb4fd1a..3583c2e 100644 |
| --- a/internal/web/home.go |
| +++ b/internal/web/home.go |
| @@ -38,8 +38,10 @@ type homePage struct { |
| // then the installed Store apps; Dock is Base's own pages. Home draws |
| // them all, in that order, in one grid. |
| Apps, Dock []tile |
| - // Ask is the chat panel, nil with the chat off. |
| - Ask *askView |
| + // Ask is the chat docked beside Home, nil with the chat off. AskOpen |
| + // draws it open on a wide screen: the member has not closed it. |
| + Ask *askView |
| + AskOpen bool |
| } |
| // Icons for the built-in tiles, in the mockup's style. |
| @@ -148,13 +150,17 @@ func (a *app) home(w http.ResponseWriter, r *http.Request) { |
| page.Lede = "Two steps until " + a.cfg.Name + "'s Base is ready." |
| } |
| if a.ask != nil { |
| - _, _, state, err := a.askLink(r.Context(), me) |
| + l, sec, state, err := a.askLink(r.Context(), me) |
| if err != nil { |
| a.logger.Error("home: equipo link", "err", err) |
| state = askUnavailable |
| } |
| v := a.newAskView(homeState(state), "home") |
| - page.Ask = &v |
| + // Docked, the conversation is on Home from the first paint. |
| + if state == askReady { |
| + a.askSnapshot(r, me, l, sec.Token, &v) |
| + } |
| + page.Ask, page.AskOpen = &v, !me.AskClosed |
| } |
| w.Header().Set("Cache-Control", "no-store") |
| a.render(w, r, "home", page) |
diff --git a/internal/web/templates/home.html b/internal/web/templates/home.html| index 3a67ce9..9f2f253 100644 |
| --- a/internal/web/templates/home.html |
| +++ b/internal/web/templates/home.html |
| @@ -1,15 +1,18 @@ |
| {{define "title"}}{{.Name}} · Base{{end}} |
| -{{define "main"}}<main class="screen home"> |
| -<div class="topbar glass"> |
| +{{/* On a wide screen Ask Base is docked open beside Home until the member closes it. */}}{{define "root"}}{{if and .Ask (not .AskOpen)}} class="desk-closed"{{end}}{{end}} |
| +{{define "main"}}<div class="shell"> |
| +{{/* The header across the top. The Base button opens Ask Base: on a wide |
| + screen it shows only while the chat is closed. */}}<header class="topbar glass"> |
| <div class="wordmark">base</div> |
| <div class="team">{{.Name}}</div> |
| -{{if .Ask}}<a class="ask" href="/ask" data-ask-open aria-haspopup="dialog" aria-controls="ask-panel">Ask Base anything</a> |
| -<a class="ask-icon" href="/ask" data-ask-open aria-haspopup="dialog" aria-controls="ask-panel" aria-label="Ask Base"><svg viewBox="0 0 24 24" aria-hidden="true"><path d="M5 5.5h14a1.5 1.5 0 0 1 1.5 1.5v8.5A1.5 1.5 0 0 1 19 17h-8l-4.5 3.5V17H5a1.5 1.5 0 0 1-1.5-1.5V7A1.5 1.5 0 0 1 5 5.5z"/><path d="M8.5 11.25h.01M12 11.25h.01M15.5 11.25h.01"/></svg></a>{{else}}<input class="ask" type="text" disabled placeholder="Ask Base anything" title="Asking Base arrives in a later slice" aria-label="Ask Base anything">{{end}} |
| -<a class="me" href="/settings" aria-label="Settings">{{.Initials}}</a> |
| -</div> |
| +{{if .Ask}}<form class="base-btn-form" method="post" action="/ask/dock"><input type="hidden" name="open" value="1"><button class="base-btn" type="submit" data-ask-open aria-controls="ask-panel" aria-label="Ask Base" title="Ask Base"><span class="mark" aria-hidden="true"></span></button></form> |
| +{{end}}<a class="me" href="/settings" aria-label="Settings">{{.Initials}}</a> |
| +</header> |
| +<main class="home" id="home"> |
| <h2 class="hello">{{.Greeting}}</h2> |
| <p class="lede">{{.Lede}}</p> |
| -<ul class="steps"> |
| +{{/* The Ask field under the greeting. It folds away while the chat is docked open. */}}{{if .Ask}}<div class="ask-slot"><div><form class="ask-field-form" method="post" action="/ask/dock"><input type="hidden" name="open" value="1"><button class="ask-field" type="submit" data-ask-open aria-controls="ask-panel"><span>Ask Base anything</span><kbd>/</kbd></button></form></div></div> |
| +{{end}}<ul class="steps"> |
| {{range .Steps}}<li class="glass{{if .Done}} done{{end}}"><span class="mark">{{if .Done}}✓{{end}}</span>{{.Label}}</li> |
| {{end}}</ul> |
| {{/* Every app in one glass panel, one grid of alike items: the Oficina |
| @@ -20,8 +23,9 @@ |
| {{end}}{{range .Dock}}{{template "app" .}} |
| {{end}}</ul> |
| </nav> |
| -{{with .Ask}}{{template "ask-panel" .}} |
| -<script type="module" src="{{asset "static/ask.js"}}"></script>{{end}} |
| -</main>{{end}} |
| +</main> |
| +{{with .Ask}}<div class="chat-col">{{template "ask-panel" .}}</div> |
| +<script type="module" src="{{asset "static/ask.js"}}"></script> |
| +{{end}}</div>{{end}} |
| {{define "app"}}<li{{if .Own}} class="own"{{end}}><a class="app" href="{{.Href}}"{{if .NewTab}} target="_blank" rel="noopener"{{end}}>{{if .Image}}<span class="icon"><img src="{{asset .Image}}" alt=""></span>{{else}}<span class="icon tile t-{{.Tint}}">{{.Icon}}</span>{{end}}<span class="label">{{.Name}}</span></a></li>{{end}} |
diff --git a/internal/web/templates/partials/chat.html b/internal/web/templates/partials/chat.html| index 3f0a925..9356c7b 100644 |
| --- a/internal/web/templates/partials/chat.html |
| +++ b/internal/web/templates/partials/chat.html |
| @@ -1,8 +1,8 @@ |
| -{{/* The chat behind "Ask Base anything": the panel over Home, and /ask. Every state's block is drawn and the one for .State shows; the panel's script moves between them. */}} |
| +{{/* The chat behind "Ask Base anything": docked beside Home, and /ask. Every state's block is drawn and the one for .State shows; the panel's script moves between them. */}} |
| {{define "ask-head"}}<div class="ask-head"><h2 id="ask-title">Ask Base</h2></div>{{end}} |
| -{{define "ask-panel"}}<dialog id="ask-panel" class="ask-panel glass" aria-labelledby="ask-title" data-ask data-state="{{.State}}"> |
| -<div class="ask-head"><h2 id="ask-title">Ask Base</h2><button class="round close" type="button" data-ask-close aria-label="Close"><svg viewBox="0 0 24 24" aria-hidden="true"><path d="M6 6l12 12M18 6L6 18"/></svg></button></div> |
| -{{template "ask-body" .}}</dialog>{{end}} |
| +{{/* Docked on Home: on a wide screen the X closes it (posting open=0, kept for the member); on a phone it closes the full-screen chat. */}}{{define "ask-panel"}}<aside id="ask-panel" class="ask-panel glass" aria-labelledby="ask-title" data-ask data-state="{{.State}}"> |
| +<div class="ask-head"><h2 id="ask-title"><span class="mark" aria-hidden="true"></span>Ask Base</h2><form class="dock-close" method="post" action="/ask/dock"><input type="hidden" name="open" value="0"><button class="round close" type="submit" data-ask-close aria-label="Close"><svg viewBox="0 0 24 24" aria-hidden="true"><path d="M6 6l12 12M18 6L6 18"/></svg></button></form></div> |
| +{{template "ask-body" .}}</aside>{{end}} |
| {{/* A card, drawn from its fields alone: the question, a link per link, a button per option (its label, posting its value) while it is open, and the line saying how it ended. The panel's script draws the same (ask.js, addCard). */}} |
| {{define "ask-card"}}<li class="msg card card-{{.Kind}}" data-card="{{.ID}}" data-revision="{{.Revision}}"><p>{{.Question}}</p> |
| {{- range .Links}}<p><a class="card-link" href="{{.URL}}" target="_blank" rel="noopener">{{.Label}}</a></p>{{end}} |
diff --git a/internal/webtest/ask_test.go b/internal/webtest/ask_test.go| index 5377b40..2a327c4 100644 |
| --- a/internal/webtest/ask_test.go |
| +++ b/internal/webtest/ask_test.go |
| @@ -116,9 +116,10 @@ func (a *testApp) noLeak(token string) { |
| func TestAskOffWithoutEquipo(t *testing.T) { |
| a := newApp(t) |
| a.signedInOwner() |
| + // Home has no chat column, no Base button and no field. |
| home := a.get("/").Body |
| - if !strings.Contains(home, `<input class="ask" type="text" disabled`) || strings.Contains(home, `href="/ask"`) || |
| - strings.Contains(home, "<dialog") { |
| + if strings.Contains(home, `class="ask`) || strings.Contains(home, "base-btn") || strings.Contains(home, `/ask`) || |
| + strings.Contains(home, "<aside") || strings.Contains(home, "<dialog") { |
| t.Errorf("chat is not off:\n%s", home) |
| } |
| if r := a.get("/ask"); r.Code != 404 { |
| @@ -132,7 +133,8 @@ func TestAskOffWithoutEquipo(t *testing.T) { |
| func TestAskFieldOpensChat(t *testing.T) { |
| a, _ := newAskApp(t) |
| home := a.get("/").Body |
| - for _, want := range []string{`<a class="ask" href="/ask"`, `<a class="ask-icon" href="/ask"`, `aria-label="Ask Base"`, `<dialog id="ask-panel"`, `action="/ask/connect"`} { |
| + for _, want := range []string{`<button class="ask-field" type="submit" data-ask-open aria-controls="ask-panel"><span>Ask Base anything</span>`, |
| + `<button class="base-btn" type="submit" data-ask-open aria-controls="ask-panel" aria-label="Ask Base"`, `<aside id="ask-panel"`, `action="/ask/connect"`} { |
| if !strings.Contains(home, want) { |
| t.Errorf("Home lacks %q:\n%s", want, home) |
| } |
diff --git a/internal/webtest/home_test.go b/internal/webtest/home_test.go| index f83670d..dfd3528 100644 |
| --- a/internal/webtest/home_test.go |
| +++ b/internal/webtest/home_test.go |
| @@ -104,9 +104,6 @@ func TestHomeTilesLinkToOrigins(t *testing.T) { |
| if !re.MatchString(body) { |
| t.Fatalf("no tile for scratchpad:\n%s", body) |
| } |
| - if !strings.Contains(body, "disabled") || !strings.Contains(body, "Ask Base anything") { |
| - t.Errorf("ask field missing or not disabled") |
| - } |
| } |
| // Finding 1: a tile links to the host Base installed the app at, even after |
| @@ -234,3 +231,108 @@ func TestEveryOficinaAppHasAnIcon(t *testing.T) { |
| } |
| } |
| } |
| + |
| +// deskClosed reports whether Home draws Ask Base closed on a wide screen: |
| +// <html class="desk-closed">. |
| +func deskClosed(t *testing.T, body string) bool { |
| + t.Helper() |
| + m := regexp.MustCompile(`<html[^>]*>`).FindString(body) |
| + if m == "" { |
| + t.Fatalf("no <html> in:\n%s", body) |
| + } |
| + return strings.Contains(m, `class="desk-closed"`) |
| +} |
| + |
| +// Home for a member with Ask Base draws the chat docked beside it, open |
| +// with the conversation, until they close it: POST /ask/dock (open=0, by |
| +// the X) draws <html class="desk-closed"> on every later visit, and open=1 |
| +// (the Base button, the field) clears it. It is theirs alone, a cross-site |
| +// post changes nothing, and without Equipo there is no chat at all. |
| +func TestHomeDocksAskOpenByDefault(t *testing.T) { |
| + a, f := newAskApp(t) |
| + a.connectEquipo(f) |
| + f.Say("Your week is clear.") |
| + home := a.get("/") |
| + if home.Code != 200 || deskClosed(t, home.Body) { |
| + t.Fatalf("Home: %d, closed %v", home.Code, deskClosed(t, home.Body)) |
| + } |
| + for _, want := range []string{ |
| + `<aside id="ask-panel" class="ask-panel glass"`, |
| + `<li class="msg coordinator"`, "Your week is clear.", |
| + `<form class="composer" method="post" action="/ask/messages">`, |
| + // The X, and the Base button and the field that bring it back. |
| + `<form class="dock-close" method="post" action="/ask/dock"><input type="hidden" name="open" value="0">`, |
| + `<form class="base-btn-form" method="post" action="/ask/dock"><input type="hidden" name="open" value="1">`, |
| + `<form class="ask-field-form" method="post" action="/ask/dock"><input type="hidden" name="open" value="1">`, |
| + } { |
| + if !strings.Contains(home.Body, want) { |
| + t.Errorf("Home lacks %q:\n%s", want, home.Body) |
| + } |
| + } |
| + if strings.Contains(home.Body, "<dialog") { |
| + t.Error("Home still draws the chat as a dialog") |
| + } |
| + |
| + if r := a.post("/ask/dock", url.Values{"open": {"0"}}); r.Code != 303 || r.Location() != "/" { |
| + t.Fatalf("close: %d %q", r.Code, r.Location()) |
| + } |
| + if !deskClosed(t, a.get("/").Body) { |
| + t.Error("closed, Home draws it open") |
| + } |
| + if r := a.postJSON("/ask/dock", url.Values{"open": {"1"}}); r.Code != 204 { |
| + t.Fatalf("open by fetch: %d %s", r.Code, r.Body) |
| + } |
| + if deskClosed(t, a.get("/").Body) { |
| + t.Error("opened again, Home draws it closed") |
| + } |
| + if r := a.postJSON("/ask/dock", url.Values{"open": {"0"}}); r.Code != 204 { |
| + t.Fatalf("close by fetch: %d %s", r.Code, r.Body) |
| + } |
| + if r := a.post("/ask/dock", url.Values{"open": {"1"}}); r.Code != 303 || r.Location() != "/" { |
| + t.Fatalf("open: %d %q", r.Code, r.Location()) |
| + } |
| + if deskClosed(t, a.get("/").Body) { |
| + t.Error("opened by the form, Home draws it closed") |
| + } |
| + for _, v := range []string{"", "2", "true"} { |
| + if r := a.post("/ask/dock", url.Values{"open": {v}}); r.Code != 400 { |
| + t.Errorf("open=%q: %d", v, r.Code) |
| + } |
| + } |
| + if r := a.postFrom("https://evil.example", "/ask/dock", url.Values{"open": {"0"}}); r.Code != 403 { |
| + t.Errorf("cross-site close: %d", r.Code) |
| + } |
| + if deskClosed(t, a.get("/").Body) { |
| + t.Error("a cross-site post closed it") |
| + } |
| + |
| + // Another member's is their own. |
| + a.post("/ask/dock", url.Values{"open": {"0"}}) |
| + a.post("/people", invite("maria@acme.co")) |
| + if r := a.signIn("maria@acme.co"); r.Code != 303 { |
| + t.Fatalf("maria sign-in: %d", r.Code) |
| + } |
| + if body := a.get("/").Body; deskClosed(t, body) || !strings.Contains(body, `<aside id="ask-panel"`) { |
| + t.Errorf("the owner's close reached another member:\n%s", body) |
| + } |
| + owner, _, err := store.MemberByEmail(context.Background(), a.DB, ownerAddress) |
| + if err != nil || !owner.AskClosed { |
| + t.Errorf("the owner's close: %v %v", owner.AskClosed, err) |
| + } |
| + |
| + // Without Equipo: no chat column, no Base button, no field. |
| + off := newApp(t) |
| + off.signedInOwner() |
| + body := off.get("/").Body |
| + for _, gone := range []string{`id="ask-panel"`, "base-btn", "ask-field", `action="/ask/dock"`, "Ask Base anything", "<aside"} { |
| + if strings.Contains(body, gone) { |
| + t.Errorf("Home without Equipo has %q:\n%s", gone, body) |
| + } |
| + } |
| + if deskClosed(t, body) { |
| + t.Error("Home without Equipo is drawn closed") |
| + } |
| + if r := off.post("/ask/dock", url.Values{"open": {"0"}}); r.Code != 404 { |
| + t.Errorf("/ask/dock without Equipo: %d", r.Code) |
| + } |
| +} |