oficina / base Public

Fit Base to a phone: one-line top bar, full-screen Ask sheet

At 390px Home's top bar wrapped the Ask field onto two lines and showed
the "/" hint. On narrow screens the team name and the hint go, the field
truncates instead of wrapping, and it is a 44px target.

The Ask panel on a phone 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; 100dvh otherwise), with a compact
sticky header, the conversation scrolling between, and safe-area room
for the notch and home indicator. The viewport meta adds viewport-fit
and interactive-widget=resizes-content; the page behind does not scroll.

A browser test at 390x844 checks every page for horizontal overflow,
the one-line top bar, and the open sheet's header, composer and 44px
targets, and saves screenshots to BASE_BROWSER_ARTIFACTS.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Paul Campbell pushed by paul@keymail.dev f8d4e7b9060ad05b50334f51e3011c8806d616f6 parent 7d7bec6
4 files changed, +196 −2
  • internal/browsertest/mobile_test.go +153 −0
  • internal/look/static/app.css +28 −1
  • internal/look/static/ask.js +14 −0
  • internal/look/templates/layout.html +1 −1
diff --git a/internal/browsertest/mobile_test.go b/internal/browsertest/mobile_test.go
new file mode 100644
index 0000000..a918dbe
--- /dev/null
+++ b/internal/browsertest/mobile_test.go
@@ -0,0 +1,153 @@
+//go:build browser
+
+package browsertest
+
+import (
+ "context"
+ "net/http"
+ "os"
+ "path/filepath"
+ "testing"
+ "time"
+
+ "github.com/chromedp/chromedp"
+
+ "amadan.net/rastrillo/rastrillo/harness"
+
+ "amadan.net/carlos/base/internal/equipo/equipotest"
+)
+
+// noOverflow fails if the page is wider than the phone's screen.
+func noOverflow(t *testing.T, rig *harness.Rig, page string) {
+ t.Helper()
+ if got := harness.Evaluate[string](rig, `(() => {
+ const w = document.documentElement.clientWidth, s = document.documentElement.scrollWidth;
+ if (s <= w) return "";
+ const wide = [...document.querySelectorAll("body *")].filter(e => e.getBoundingClientRect().right > w + 0.5)
+ .slice(0, 5).map(e => e.tagName.toLowerCase() + "." + e.className + " " + Math.round(e.getBoundingClientRect().right));
+ return s + " > " + w + ": " + wide.join(", ");
+ })()`); got != "" {
+ t.Errorf("%s overflows a 390px screen: %s", page, got)
+ }
+}
+
+// mobileShot saves a full-page PNG when BASE_BROWSER_ARTIFACTS is set.
+func mobileShot(t *testing.T, rig *harness.Rig, name string) {
+ t.Helper()
+ dir := os.Getenv("BASE_BROWSER_ARTIFACTS")
+ if dir == "" {
+ return
+ }
+ drive(t, rig, chromedp.Func(func(ctx context.Context, target *chromedp.Target) error {
+ _, err := chromedp.Evaluate[bool](`document.fonts.ready.then(() => true)`, chromedp.EvalAwaitPromise)(ctx, target)
+ return err
+ }))
+ var png []byte
+ drive(t, rig, chromedp.Func(func(ctx context.Context, target *chromedp.Target) error {
+ var err error
+ png, err = chromedp.FullScreenshot(100)(ctx, target)
+ return err
+ }))
+ if err := os.MkdirAll(dir, 0o755); err != nil {
+ t.Fatal(err)
+ }
+ if err := os.WriteFile(filepath.Join(dir, name+".png"), png, 0o644); err != nil {
+ t.Fatal(err)
+ }
+}
+
+// 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 screen.
+func TestMobile(t *testing.T) {
+ f := equipotest.New(t)
+ f.Reply = func(string) string {
+ return "You can ask me to plan work, check on a project, or start a task. What would you like to do?"
+ }
+ var b *baseApp
+ rig := newRig(t, func(origin string) http.Handler {
+ cfg := baseConfig(origin)
+ cfg.EquipoOrigin = f.URL
+ b = newBase(t, cfg)
+ return b.handler
+ })
+ drive(t, rig, chromedp.EmulateViewport(390, 844, chromedp.EmulateMobile, chromedp.EmulateScale(3)))
+ drive(t, rig, chromedp.Navigate(rig.Origin+"/signin"), chromedp.WaitVisible(chromedp.CSS(`input[name="address"]`)))
+ noOverflow(t, rig, "sign-in")
+ signInByEmail(t, rig, rig.Origin, b.mail)
+
+ // Home: the top bar on one line, no "/" hint.
+ noOverflow(t, rig, "Home")
+ if got := harness.Evaluate[string](rig, `(() => {
+ const bar = document.querySelector(".topbar"), ask = document.querySelector("a.ask");
+ const tops = [...bar.children].filter(e => getComputedStyle(e).display !== "none").map(e => Math.round(e.getBoundingClientRect().top + e.getBoundingClientRect().height / 2));
+ const problems = [];
+ if (Math.max(...tops) - Math.min(...tops) > 2) problems.push("top bar wraps: " + tops.join(","));
+ if (ask.getBoundingClientRect().height > 44) problems.push("Ask field is " + ask.getBoundingClientRect().height + "px tall");
+ if (ask.scrollWidth > ask.clientWidth) problems.push("Ask field text overflows");
+ const hint = getComputedStyle(ask, "::after");
+ if (hint.content !== "none" && hint.display !== "none") problems.push("shows the / hint");
+ return problems.join("; ");
+ })()`); got != "" {
+ t.Errorf("Home's top bar on a phone: %s", got)
+ }
+ mobileShot(t, rig, "1-home")
+
+ // The panel before connecting.
+ drive(t, rig, chromedp.Click(chromedp.CSS(`a.ask`)),
+ chromedp.WaitVisible(chromedp.CSS(`#ask-panel [data-when="connect"] button`)))
+ mobileShot(t, rig, "2-panel-connect")
+
+ // Connect from the panel: the code page, then back to the open panel.
+ drive(t, rig, chromedp.Click(chromedp.CSS(`#ask-panel [data-when="connect"] button`)), chromedp.WaitVisible(chromedp.CSS(`p.code`)))
+ noOverflow(t, rig, "the connect page")
+ mobileShot(t, rig, "3-connect-code")
+ if err := f.Approve(harness.Evaluate[string](rig, `document.querySelector("p.code").textContent`)); err != nil {
+ t.Fatal(err)
+ }
+ if _, err := b.db.Exec(`UPDATE equipo_links SET polled_at = ?`, time.Now().Add(-time.Minute).UTC()); err != nil {
+ t.Fatal(err)
+ }
+ drive(t, rig, chromedp.Click(chromedp.CSS(`form[action="/ask/connect/check"] button`)),
+ chromedp.WaitVisible(chromedp.CSS(`#ask-panel textarea`)))
+
+ // Mid-conversation: the sheet fills the screen, the header is at the
+ // top, the composer on screen at the bottom, targets 44px.
+ 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)),
+ chromedp.Poll[chromedp.Void](`(() => { const r = document.querySelector("#ask-panel").getBoundingClientRect(); return r.left === 0 && r.top === 0 })()`,
+ chromedp.WithPollingTimeout(3*time.Second)))
+ if got := harness.Evaluate[string](rig, `(() => {
+ const vh = window.visualViewport.height, vw = window.visualViewport.width, problems = [];
+ const p = document.querySelector("#ask-panel").getBoundingClientRect();
+ if (Math.round(p.width) !== Math.round(vw) || Math.round(p.height) !== Math.round(vh)) problems.push("sheet " + p.width + "x" + p.height);
+ const head = document.querySelector("#ask-panel .ask-head").getBoundingClientRect();
+ if (head.top < 0 || head.top > 1) problems.push("header at " + head.top);
+ const c = document.querySelector("#ask-panel form.composer").getBoundingClientRect();
+ if (c.top < 0 || c.bottom > vh + 0.5 || c.height === 0) problems.push("composer at " + c.top + "-" + c.bottom + " of " + vh);
+ for (const el of document.querySelectorAll("#ask-panel .ask-head .btn, #ask-panel form.composer .btn, #ask-panel textarea")) {
+ const r = el.getBoundingClientRect();
+ if (r.height < 44 || r.width < 44) problems.push(el.textContent.trim() + " is " + r.width + "x" + r.height);
+ }
+ const m = document.querySelector("#ask-panel .msg.coordinator").getBoundingClientRect();
+ if (m.right > vw) problems.push("a message overflows");
+ return problems.join("; ");
+ })()`); got != "" {
+ t.Errorf("the panel on a phone: %s", got)
+ }
+ mobileShot(t, rig, "4-panel-conversation")
+ drive(t, rig, chromedp.KeyEvent("\u001b"))
+
+ for _, p := range []struct{ path, wait, name string }{
+ {"/store", ".sheet", "5-store"},
+ {"/people", ".sheet", "6-people"},
+ {"/settings", ".sheet", "7-settings"},
+ {"/ask", ".ask-page .composer", "8-ask"},
+ } {
+ drive(t, rig, chromedp.Navigate(rig.Origin+p.path), chromedp.WaitVisible(chromedp.CSS(p.wait)))
+ noOverflow(t, rig, p.path)
+ mobileShot(t, rig, p.name)
+ }
+}
diff --git a/internal/look/static/app.css b/internal/look/static/app.css
index 2463fc8..1bbfe6e 100644
--- a/internal/look/static/app.css
+++ b/internal/look/static/app.css
@@ -220,9 +220,36 @@ dialog.ask-panel::backdrop { background: rgba(10,12,30,.38); }
.ask-page .thread { max-height: none; }
.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
+ the top, the conversation scrolling between, and room for the notch and
+ the home indicator. */
@media (max-width: 600px) {
- dialog.ask-panel { inset: 0; width: 100%; border-radius: 0; }
+ .home { padding: 12px 12px 20px; }
+ .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: flex; }
+ a.ask::after { content: none; }
+ .ask, a.ask { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
+ .me { flex: none; }
+ .hello { margin-top: 32px; }
+ .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); }
+ dialog.ask-panel .ask-head { position: sticky; top: 0; padding: max(8px, env(safe-area-inset-top)) 8px 8px 16px; }
+ dialog.ask-panel .ask-head h2 { font-size: 18px; }
+ dialog.ask-panel .composer { padding: 8px 12px max(12px, env(safe-area-inset-bottom)); }
+ .thread { padding: 14px 12px; }
.msg { max-width: 92%; }
+ .ask-page { min-height: calc(100dvh - 20px); }
}
/* Scratchpad's shared note: a field that grows past one control height. */
diff --git a/internal/look/static/ask.js b/internal/look/static/ask.js
index e56face..ece6485 100644
--- a/internal/look/static/ask.js
+++ b/internal/look/static/ask.js
@@ -262,8 +262,22 @@ function start(root) {
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");
+ }
+ if (vv) {
+ vv.addEventListener("resize", () => { if (dialog.open) fit(); });
+ vv.addEventListener("scroll", () => { if (dialog.open) fit(); });
+ }
+
function open() {
if (dialog.open) return;
+ fit();
dialog.showModal();
load().then(() => {
const first = root.dataset.state === "ready" ? field : dialog.querySelector("[data-when]:not([hidden]) .btn");
diff --git a/internal/look/templates/layout.html b/internal/look/templates/layout.html
index 2140a88..157e490 100644
--- a/internal/look/templates/layout.html
+++ b/internal/look/templates/layout.html
@@ -2,7 +2,7 @@
<html lang="en">
<head>
<meta charset="utf-8">
-<meta name="viewport" content="width=device-width, initial-scale=1">
+<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover, interactive-widget=resizes-content">
<title>{{block "title" .}}Base{{end}}</title>
{{block "head" .}}{{end}}
<link rel="preload" href="/static/fonts/timeless/1.094/TimelessSansVF.woff2" as="font" type="font/woff2" crossorigin>