oficina / base Public

Fold Oficina apps that don't fit the rail under More, or keep it expanded

Collapsed (the default), the rail shows as many apps as its height
allows and the last spot becomes More: a <details> whose glass panel,
beside the rail, lists the rest (new tab, rel=noopener) and holds a
Keep expanded switch. How many fit is CSS's work: entries are 72px and
container queries on the rail's height pick the cut, so it adapts on
resize, never jumps, and needs no script. rail.js only closes the panel
on Escape or a click elsewhere and gives focus back to More.

Keep expanded is a POST (303 back to Home) stored on the member
(members.rail_expanded), so it holds on every device and sign-in. Kept
expanded, the rail lists every app, scrolls if it must and ends in a
Collapse button. Phones are unchanged.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Paul Campbell pushed by paul@keymail.dev 9f463133272c5a688c15437d4fb8ff436e6fc943 parent 8e5750d
11 files changed, +516 −35
  • docs/copy-pending.md +4 −0
  • internal/browsertest/oficina_test.go +212 −22
  • internal/look/static/app.css +76 −9
  • internal/look/static/rail.js +23 −0
  • internal/store/migrations/0007_rail_expanded.sql +3 −0
  • internal/store/rail.go +29 −0
  • internal/store/rail_test.go +44 −0
  • internal/web/app.go +1 −0
  • internal/web/home.go +31 −0
  • internal/web/templates/home.html +14 −2
  • internal/webtest/home_test.go +79 −2
diff --git a/docs/copy-pending.md b/docs/copy-pending.md
index dd1571b..b0db8df 100644
--- a/docs/copy-pending.md
+++ b/docs/copy-pending.md
@@ -273,5 +273,9 @@ Review 5 (pending): "Ask Base anything", the chat with Equipo's coordinator.
| internal/config/oficina.go | Start-up refusal: the same id twice (operator-facing log) | BASE_OFICINA_APPS lists {id} twice |
| internal/config/oficina.go | Start-up refusal: an address that is not https and a hostname (operator-facing log) | BASE_OFICINA_APPS: {id}'s address {value} must be https:// and a hostname only |
| README.md | Settings: the BASE_OFICINA_APPS bullet (new lines only) | `BASE_OFICINA_APPS` lists your team's Oficina apps, which Home shows down the left (as tiles on a phone), each opening in a new tab. Write each as `id=address`, separated by commas, in the order you want them, such as `calendar=https://calendar.oficina.works,fichas=https://fichas.oficina.works`. The ids are `calendar`, `docs`, `sheets`, `slides`, `memoria`, `calls`, `fichas` and `equipo`, and each address is `https://` and a hostname only. Base refuses to start with an id it doesn't know. Without it, Home lists no Oficina apps. |
+| internal/web/templates/home.html | Oficina rail, the last entry when not every app fits (under a ⋯ glyph; opens a panel of the rest). Same word as the Ask panel's ⋯ button | More |
+| internal/web/templates/home.html | The More panel's accessible name (a region) | More Oficina apps |
+| internal/web/templates/home.html | The More panel's switch (on: the rail lists every app, on every device) | Keep expanded |
+| internal/web/templates/home.html | Oficina rail kept expanded, its last entry (puts More back) | Collapse |
Activity lines in the status ("Adding a project…" and the like) are Equipo's own labels, shown as Equipo sends them.
diff --git a/internal/browsertest/oficina_test.go b/internal/browsertest/oficina_test.go
index e2ab388..b614fa4 100644
--- a/internal/browsertest/oficina_test.go
+++ b/internal/browsertest/oficina_test.go
@@ -12,6 +12,8 @@ import (
"testing"
"time"
+ "github.com/chromedp/cdproto/cdp"
+ "github.com/chromedp/cdproto/network"
"github.com/chromedp/chromedp"
"amadan.net/rastrillo/rastrillo/harness"
@@ -99,7 +101,7 @@ func TestOficinaRail(t *testing.T) {
if (rail.getAttribute("aria-label") !== "Oficina") problems.push("rail labelled " + rail.getAttribute("aria-label"));
const phone = document.querySelector("section.oficina");
if (phone && phone.checkVisibility()) problems.push("the phone's tiles show too");
- const links = [...rail.querySelectorAll("a")];
+ const links = [...rail.querySelectorAll(":scope > a.rail-app")];
const got = links.map(a => ({Name: a.textContent.trim(), Href: a.getAttribute("href")}));
if (JSON.stringify(got) !== JSON.stringify(want)) problems.push("apps " + JSON.stringify(got));
for (const a of links) {
@@ -155,27 +157,6 @@ func TestOficinaRail(t *testing.T) {
t.Errorf("after scrolling Home: %s", got)
}
- // On a short screen the rail scrolls by itself: the keyboard reaches the
- // last app and it is on screen, inside the rail.
- drive(t, rig, chromedp.EmulateViewport(1280, 600), chromedp.Navigate(rig.Origin+"/"), chromedp.WaitVisible(chromedp.CSS(".hello")))
- keys := []chromedp.Action[chromedp.Void]{}
- for range 3 + len(apps) - 1 {
- keys = append(keys, chromedp.KeyEvent("\t"))
- }
- drive(t, rig, keys...)
- if got := harness.Evaluate[string](rig, `(() => {
- const a = document.activeElement, rail = document.querySelector("nav.rail");
- if (!a.matches("nav.rail a:last-child")) return "focus is on " + a.outerHTML.slice(0, 80);
- const r = a.getBoundingClientRect(), rr = rail.getBoundingClientRect();
- if (r.top < 0 || r.bottom > window.innerHeight) return "last app at " + r.top + "-" + r.bottom + " of " + window.innerHeight;
- if (r.top < rr.top - 0.5 || r.bottom > rr.bottom + 0.5) return "last app outside the rail: " + r.top + "-" + r.bottom + ", rail " + rr.top + "-" + rr.bottom;
- if (rr.bottom > window.innerHeight + 0.5 && window.scrollY === 0) return "rail runs off the screen at " + rr.bottom;
- return "";
- })()`); got != "" {
- t.Errorf("at 1280x600: %s", got)
- }
- viewportShot(t, rig, "home-desktop-short")
- drive(t, rig, chromedp.EmulateViewport(1280, 800))
drive(t, rig, chromedp.Navigate(rig.Origin+"/"), chromedp.WaitVisible(chromedp.CSS(".hello")))
viewportShot(t, rig, "home-desktop")
}
@@ -220,3 +201,212 @@ func TestAskPanelBesideRail(t *testing.T) {
chromedp.Poll[chromedp.Void](`!document.querySelector("#ask-panel").open`, chromedp.WithPollingTimeout(5*time.Second)))
}
}
+
+// railState is what the rail shows: the apps in it, whether More shows and
+// the apps its panel lists while open, as names; and any problem with how
+// it sits on screen.
+const railStateJS = `(() => {
+ const rail = document.querySelector("nav.rail"), vw = document.documentElement.clientWidth, vh = window.innerHeight;
+ const rr = rail.getBoundingClientRect(), problems = [];
+ const shown = [...rail.querySelectorAll(":scope > a.rail-app")].filter(a => a.checkVisibility());
+ const more = rail.querySelector(":scope > details.rail-more");
+ const moreShown = !!more && more.checkVisibility();
+ const panel = more ? more.querySelector(".rail-panel") : null;
+ const listed = panel && more.open ? [...panel.querySelectorAll("a")].filter(a => a.checkVisibility()) : [];
+ const entries = shown.concat(moreShown ? [more.querySelector("summary")] : []);
+ for (const e of entries) {
+ const r = e.getBoundingClientRect();
+ if (r.width < 44 || r.height < 44) problems.push(e.textContent.trim() + " is " + r.width + "x" + r.height);
+ if (r.top < rr.top - 0.5 || r.bottom > rr.bottom + 0.5) problems.push(e.textContent.trim() + " sticks out of the rail");
+ if (r.bottom > vh) problems.push(e.textContent.trim() + " is below the screen");
+ }
+ if (panel && more.open) {
+ const p = panel.getBoundingClientRect();
+ if (panel.getAttribute("role") !== "region" || panel.getAttribute("aria-label") !== "More Oficina apps") problems.push("panel not a labelled region");
+ if (p.left < rr.right || p.right > vw || p.top < 0 || p.bottom > vh) problems.push("panel at " + [p.left, p.top, p.right, p.bottom].join(","));
+ for (const e of listed.concat([...panel.querySelectorAll("button")])) {
+ const r = e.getBoundingClientRect();
+ if (r.height < 44) problems.push(e.textContent.trim() + " in the panel is " + r.height + " tall");
+ if (e.matches("a") && (e.target !== "_blank" || e.rel !== "noopener")) problems.push(e.textContent + " target/rel");
+ }
+ const hit = document.elementFromPoint(p.left + p.width / 2, p.top + 12);
+ if (!panel.contains(hit)) problems.push("the panel is under " + (hit && hit.className));
+ }
+ if (document.documentElement.scrollWidth > vw) problems.push("page is " + document.documentElement.scrollWidth + " wide");
+ return JSON.stringify({rail: shown.map(a => a.textContent.trim()), more: moreShown, panel: listed.map(a => a.textContent.trim()),
+ expanded: rail.classList.contains("expanded"), problems: problems.join("; ")});
+})()`
+
+type railState struct {
+ Rail, Panel []string
+ More bool
+ Expanded bool
+ Problems string
+}
+
+func readRail(t *testing.T, rig *harness.Rig) railState {
+ t.Helper()
+ var s railState
+ if err := json.Unmarshal([]byte(harness.Evaluate[string](rig, railStateJS)), &s); err != nil {
+ t.Fatal(err)
+ }
+ return s
+}
+
+func names(apps []config.OficinaApp) []string {
+ var out []string
+ for _, a := range apps {
+ out = append(out, a.Name)
+ }
+ return out
+}
+
+func same(a, b []string) bool { return fmt.Sprint(a) == fmt.Sprint(b) }
+
+// tabThrough presses Tab until focus leaves the rail, opening More with
+// Enter on the way, and returns the hrefs (or labels) focus visited in it.
+func tabThrough(t *testing.T, rig *harness.Rig) []string {
+ t.Helper()
+ drive(t, rig, chromedp.Evaluate[chromedp.Void](`document.activeElement.blur(), window.scrollTo(0, 0)`))
+ var seen []string
+ for range 30 {
+ drive(t, rig, chromedp.KeyEvent("\t"))
+ at := harness.Evaluate[string](rig, `(() => { const a = document.activeElement;
+ if (!a.closest("nav.rail")) return "";
+ if (!a.matches(":focus-visible")) return "no visible focus on " + a.textContent.trim();
+ return a.getAttribute("href") || a.textContent.trim(); })()`)
+ if at == "" && len(seen) > 0 {
+ break
+ }
+ if at == "" {
+ continue
+ }
+ seen = append(seen, at)
+ if at == "More" && !harness.Evaluate[bool](rig, `document.querySelector("details.rail-more").open`) {
+ drive(t, rig, chromedp.KeyEvent("\r"))
+ }
+ }
+ return seen
+}
+
+func reachesAll(t *testing.T, seen []string, apps []config.OficinaApp, mode string) {
+ t.Helper()
+ got := map[string]bool{}
+ for _, s := range seen {
+ got[s] = true
+ }
+ for _, a := range apps {
+ if !got[a.Origin+"/"] {
+ t.Errorf("%s: the keyboard never reaches %s (visited %v)", mode, a.Name, seen)
+ }
+ }
+}
+
+// The rail shows as many apps as fit; the last spot is More, whose panel
+// lists the rest with the Keep expanded switch. Kept expanded, the rail
+// lists every app and scrolls, ending in Collapse; that holds across
+// sign-ins. All of it works with scripts off too.
+func TestRailMoreInBrowser(t *testing.T) {
+ f := equipotest.New(t)
+ apps := teamApps(t)
+ all := names(apps)
+ var b *baseApp
+ rig := newRig(t, func(origin string) http.Handler {
+ cfg := baseConfig(origin)
+ cfg.EquipoOrigin = f.URL
+ cfg.OficinaApps = apps
+ b = newBase(t, cfg)
+ return b.handler
+ })
+ drive(t, rig, chromedp.EmulateViewport(1280, 600))
+ signInByEmail(t, rig, rig.Origin, b.mail)
+ home := func() {
+ t.Helper()
+ drive(t, rig, chromedp.Navigate(rig.Origin+"/"), chromedp.WaitVisible(chromedp.CSS(".hello")))
+ }
+
+ // 1280x600: some apps, then More; the panel lists the rest, in order.
+ home()
+ s := readRail(t, rig)
+ if !s.More || s.Expanded || len(s.Rail) == 0 || len(s.Rail) >= len(all) || !same(s.Rail, all[:len(s.Rail)]) || s.Problems != "" {
+ t.Fatalf("collapsed at 1280x600: %+v", s)
+ }
+ viewportShot(t, rig, "more-closed")
+ drive(t, rig, chromedp.Click(chromedp.CSS(`details.rail-more summary`)), chromedp.WaitVisible(chromedp.CSS(`.rail-panel`)))
+ s = readRail(t, rig)
+ if !same(s.Panel, all[len(s.Rail):]) || s.Problems != "" {
+ t.Errorf("More's panel at 1280x600: %+v", s)
+ }
+ viewportShot(t, rig, "more-open")
+
+ // Escape from inside the panel closes it and gives focus back to More;
+ // so does a click elsewhere.
+ drive(t, rig, chromedp.KeyEvent("\t"),
+ chromedp.Poll[chromedp.Void](`document.activeElement.matches(".rail-panel a")`, chromedp.WithPollingTimeout(3*time.Second)),
+ chromedp.KeyEvent("\u001b"),
+ chromedp.Poll[chromedp.Void](`!document.querySelector("details.rail-more").open`, chromedp.WithPollingTimeout(3*time.Second)),
+ chromedp.Poll[chromedp.Void](`document.activeElement.matches("details.rail-more summary")`, chromedp.WithPollingTimeout(3*time.Second)))
+ drive(t, rig, chromedp.Click(chromedp.CSS(`details.rail-more summary`)), chromedp.WaitVisible(chromedp.CSS(`.rail-panel`)),
+ chromedp.Click(chromedp.CSS(`.hello`)),
+ chromedp.Poll[chromedp.Void](`!document.querySelector("details.rail-more").open`, chromedp.WithPollingTimeout(3*time.Second)))
+ reachesAll(t, tabThrough(t, rig), apps, "collapsed")
+
+ // Tall enough for every app: no More.
+ drive(t, rig, chromedp.EmulateViewport(1280, 1000))
+ home()
+ if s := readRail(t, rig); s.More || !same(s.Rail, all) || s.Problems != "" {
+ t.Errorf("at 1280x1000: %+v", s)
+ }
+
+ // Keep expanded: every app, the rail scrolls, Collapse is last.
+ drive(t, rig, chromedp.EmulateViewport(1280, 600))
+ home()
+ drive(t, rig, chromedp.Click(chromedp.CSS(`details.rail-more summary`)), chromedp.WaitVisible(chromedp.CSS(`.rail-panel button[role="switch"]`)),
+ chromedp.Click(chromedp.CSS(`.rail-panel button[role="switch"]`)), chromedp.WaitVisible(chromedp.CSS(`nav.rail.expanded`)))
+ expanded := func(when string) {
+ t.Helper()
+ s := readRail(t, rig)
+ if !s.Expanded || s.More || !same(s.Rail, all) {
+ t.Errorf("%s: %+v", when, s)
+ }
+ if got := harness.Evaluate[string](rig, `(() => {
+ const rail = document.querySelector("nav.rail"), last = rail.lastElementChild;
+ if (!last.matches("form.rail-collapse") || last.textContent.trim() !== "Collapse") return "last entry is " + last.outerHTML.slice(0, 80);
+ if (rail.scrollHeight <= rail.clientHeight) return "the rail does not scroll";
+ if (document.documentElement.scrollWidth > document.documentElement.clientWidth) return "page overflows";
+ return "";
+ })()`); got != "" {
+ t.Errorf("%s: %s", when, got)
+ }
+ }
+ expanded("after Keep expanded")
+ viewportShot(t, rig, "expanded")
+ reachesAll(t, tabThrough(t, rig), apps, "expanded")
+
+ // It holds in a new sign-in on a browser that has never seen Base (no
+ // cookies at all), so it is the member's, not the browser's.
+ drive(t, rig, chromedp.Func(func(ctx context.Context, target *chromedp.Target) error {
+ _, err := cdp.Call(ctx, target, network.ClearBrowserCookies, cdp.Empty{})
+ return err
+ }))
+ signInByEmail(t, rig, rig.Origin, b.mail)
+ expanded("after signing in again")
+
+ // Collapse puts More back.
+ drive(t, rig, chromedp.Click(chromedp.CSS(`form.rail-collapse button`)), chromedp.WaitVisible(chromedp.CSS(`details.rail-more summary`)))
+ if s := readRail(t, rig); s.Expanded || !s.More {
+ t.Errorf("after Collapse: %+v", s)
+ }
+
+ // Scripts off: More is a <details>, the switch and Collapse plain POSTs.
+ drive(t, rig, scriptsDisabled(true))
+ home()
+ drive(t, rig, chromedp.Click(chromedp.CSS(`details.rail-more summary`)), chromedp.WaitVisible(chromedp.CSS(`.rail-panel button[role="switch"]`)))
+ if s := readRail(t, rig); !same(s.Panel, all[len(s.Rail):]) || s.Problems != "" {
+ t.Errorf("More with scripts off: %+v", s)
+ }
+ drive(t, rig, chromedp.Click(chromedp.CSS(`.rail-panel button[role="switch"]`)), chromedp.WaitVisible(chromedp.CSS(`nav.rail.expanded`)))
+ expanded("Keep expanded with scripts off")
+ drive(t, rig, chromedp.Click(chromedp.CSS(`form.rail-collapse button`)), chromedp.WaitVisible(chromedp.CSS(`details.rail-more summary`)))
+ drive(t, rig, scriptsDisabled(false))
+}
diff --git a/internal/look/static/app.css b/internal/look/static/app.css
index 9dae1d5..bbcdbda 100644
--- a/internal/look/static/app.css
+++ b/internal/look/static/app.css
@@ -123,20 +123,87 @@ button.alt[aria-busy="true"] { cursor: progress; }
.home-body { flex: 1; min-width: 0; display: flex; flex-direction: column; }
/* The Oficina rail: a slim column of glass down the left, under the top bar.
Each app is its icon with its name under it, a link that opens it in a new tab.
- It sticks when Home scrolls, and on a short screen scrolls by itself. Its
- height fits the screen below the top bar (117px: Home's padding, the top bar
- and the gap under it), so every entry is on screen or a scroll away in it. */
+ It sticks when Home scrolls. Its height fits the screen below the top bar
+ (117px: Home's padding, the top bar and the gap under it). Collapsed (the
+ default) it shows as many apps as fit and the last spot is More; kept
+ expanded it lists every app, scrolls if it must, and ends in Collapse. */
.rail { flex: none; width: 80px; margin-top: 16px; padding: 8px 6px; border-radius: 18px;
display: flex; flex-direction: column; gap: 4px;
- position: sticky; top: 16px; align-self: flex-start;
- height: max(160px, calc(100dvh - 117px));
+ position: sticky; top: 16px; z-index: 3; align-self: flex-start;
+ height: max(160px, calc(100dvh - 117px)); container: oficina-rail / size;
overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin; }
-.rail-app { flex: none; }
-.rail-app { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 9px 2px 8px; border-radius: 12px;
- color: var(--frost); text-decoration: none; font-size: 12px; font-weight: 500; line-height: 1.2; transition: background .2s; }
+.rail.collapsed { overflow: visible; }
+/* Every entry is 72px tall, so the rail's height says how many fit. */
+.rail-app { flex: none; height: 72px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
+ width: 100%; padding: 0 2px; border: 0; border-radius: 12px; background: none; cursor: pointer;
+ color: var(--frost); text-decoration: none; font: inherit; font-size: 12px; font-weight: 500; line-height: 1.2; transition: background .2s; }
.rail-app img { width: 36px; height: 36px; display: block; }
-.rail-app:hover { background: rgba(238,242,248,.1); }
+.rail-app:hover, .rail-more[open] > summary { background: rgba(238,242,248,.1); }
.rail-app:focus-visible { outline-offset: -2px; background: rgba(238,242,248,.1); }
+/* More and Collapse: a round glass glyph in place of an app's icon. */
+.rail-app .glyph { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center;
+ background: rgba(238,242,248,.08); box-shadow: inset 0 0 0 1px rgba(238,242,248,.2); }
+.rail-app .glyph svg { width: 20px; height: 20px; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; fill: none; }
+.rail-more .glyph svg { stroke-width: 3.2; }
+.rail-more, .rail-collapse { flex: none; }
+.rail-more { display: none; position: relative; }
+.rail-more > summary { list-style: none; }
+.rail-more > summary::-webkit-details-marker { display: none; }
+/* More's panel opens beside the rail, its foot level with More's. */
+.rail-panel { position: absolute; left: calc(100% + 18px); bottom: 0; width: 224px; max-height: calc(100dvh - 120px); overflow-y: auto;
+ padding: 6px; border-radius: 14px;
+ background: linear-gradient(rgba(238,242,248,.08), rgba(238,242,248,.04)), rgb(24,28,62);
+ box-shadow: inset 0 1px 0 rgba(255,255,255,.18), 0 18px 40px -12px rgba(8,12,22,.8); }
+.rail-panel-apps { display: flex; flex-direction: column; }
+.rail-panel-app { display: flex; align-items: center; gap: 12px; min-height: 44px; padding: 0 10px; border-radius: 8px;
+ color: var(--frost); text-decoration: none; font-size: 15px; font-weight: 500; }
+.rail-panel-app img { width: 28px; height: 28px; display: block; }
+.rail-panel form { margin: 6px 0 0; padding-top: 6px; border-top: 1px solid rgba(238,242,248,.12); }
+.switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; width: 100%; min-height: 44px; padding: 0 10px;
+ border: 0; border-radius: 8px; background: none; color: var(--frost); font: inherit; font-size: 15px; font-weight: 500; cursor: pointer; }
+.switch i { flex: none; position: relative; width: 36px; height: 22px; border-radius: 11px;
+ background: rgba(238,242,248,.12); box-shadow: inset 0 0 0 1px rgba(238,242,248,.35); }
+.switch i::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: var(--haze); }
+.rail-panel-app:hover, .rail-panel-app:focus-visible, .switch:hover, .switch:focus-visible { background: rgba(238,242,248,.1); }
+.rail-panel-app:focus-visible, .switch:focus-visible { outline-offset: -2px; }
+/* How many apps fit: S entries need 76S - 4px of the rail's inner height.
+ When the apps outnumber S, the rail shows the first S - 1 and More, and
+ More's panel hides those S - 1. Eight apps (every one Base knows) fit
+ from 604px up. */
+@container oficina-rail (height < 148px) {
+ .rail.collapsed > a.rail-app:nth-of-type(n+2), .rail.collapsed > a.rail-app:nth-of-type(1):not(:last-of-type) { display: none; }
+ .rail.collapsed > a.rail-app:nth-of-type(2) ~ .rail-more { display: block; }
+}
+@container oficina-rail (148px <= height < 224px) {
+ .rail.collapsed > a.rail-app:nth-of-type(n+3), .rail.collapsed > a.rail-app:nth-of-type(2):not(:last-of-type) { display: none; }
+ .rail.collapsed > a.rail-app:nth-of-type(3) ~ .rail-more { display: block; }
+ .rail-panel-app:nth-of-type(-n+1) { display: none; }
+}
+@container oficina-rail (224px <= height < 300px) {
+ .rail.collapsed > a.rail-app:nth-of-type(n+4), .rail.collapsed > a.rail-app:nth-of-type(3):not(:last-of-type) { display: none; }
+ .rail.collapsed > a.rail-app:nth-of-type(4) ~ .rail-more { display: block; }
+ .rail-panel-app:nth-of-type(-n+2) { display: none; }
+}
+@container oficina-rail (300px <= height < 376px) {
+ .rail.collapsed > a.rail-app:nth-of-type(n+5), .rail.collapsed > a.rail-app:nth-of-type(4):not(:last-of-type) { display: none; }
+ .rail.collapsed > a.rail-app:nth-of-type(5) ~ .rail-more { display: block; }
+ .rail-panel-app:nth-of-type(-n+3) { display: none; }
+}
+@container oficina-rail (376px <= height < 452px) {
+ .rail.collapsed > a.rail-app:nth-of-type(n+6), .rail.collapsed > a.rail-app:nth-of-type(5):not(:last-of-type) { display: none; }
+ .rail.collapsed > a.rail-app:nth-of-type(6) ~ .rail-more { display: block; }
+ .rail-panel-app:nth-of-type(-n+4) { display: none; }
+}
+@container oficina-rail (452px <= height < 528px) {
+ .rail.collapsed > a.rail-app:nth-of-type(n+7), .rail.collapsed > a.rail-app:nth-of-type(6):not(:last-of-type) { display: none; }
+ .rail.collapsed > a.rail-app:nth-of-type(7) ~ .rail-more { display: block; }
+ .rail-panel-app:nth-of-type(-n+5) { display: none; }
+}
+@container oficina-rail (528px <= height < 604px) {
+ .rail.collapsed > a.rail-app:nth-of-type(n+8), .rail.collapsed > a.rail-app:nth-of-type(7):not(:last-of-type) { display: none; }
+ .rail.collapsed > a.rail-app:nth-of-type(8) ~ .rail-more { display: block; }
+ .rail-panel-app:nth-of-type(-n+6) { display: none; }
+}
/* On a phone the same apps are tiles above the dock (see the phone rules). */
.oficina { display: none; }
.oficina h3 { margin: 0 0 12px; font-size: 13px; font-weight: 600; letter-spacing: .02em; color: var(--haze); }
diff --git a/internal/look/static/rail.js b/internal/look/static/rail.js
new file mode 100644
index 0000000..867639f
--- /dev/null
+++ b/internal/look/static/rail.js
@@ -0,0 +1,23 @@
+// The Oficina rail's More panel. Without scripts it is a plain <details>;
+// with them, Escape and a click elsewhere close it, and Escape (or opening
+// an app from it) gives focus back to More. How many apps the rail shows is
+// CSS's doing (container queries), so nothing here moves the layout.
+const more = document.querySelector("nav.rail details.rail-more");
+if (more) {
+ const summary = more.querySelector("summary");
+ const shut = (refocus) => {
+ if (!more.open) return;
+ more.open = false;
+ if (refocus) summary.focus();
+ };
+ document.addEventListener("keydown", (e) => {
+ // The Ask panel, when open, has Escape to itself.
+ if (e.key !== "Escape" || !more.open || document.querySelector("dialog[open]")) return;
+ e.preventDefault();
+ shut(true);
+ });
+ document.addEventListener("click", (e) => {
+ if (!more.contains(e.target)) shut(more.contains(document.activeElement));
+ });
+ for (const a of more.querySelectorAll(".rail-panel a")) a.addEventListener("click", () => shut(true));
+}
diff --git a/internal/store/migrations/0007_rail_expanded.sql b/internal/store/migrations/0007_rail_expanded.sql
new file mode 100644
index 0000000..98104f4
--- /dev/null
+++ b/internal/store/migrations/0007_rail_expanded.sql
@@ -0,0 +1,3 @@
+-- Keep expanded: the member keeps Home's Oficina rail listing every app
+-- instead of folding what doesn't fit under More. Theirs on every device.
+ALTER TABLE members ADD COLUMN rail_expanded integer NOT NULL DEFAULT 0;
diff --git a/internal/store/rail.go b/internal/store/rail.go
new file mode 100644
index 0000000..3c008d5
--- /dev/null
+++ b/internal/store/rail.go
@@ -0,0 +1,29 @@
+package store
+
+import (
+ "context"
+ "database/sql"
+ "fmt"
+)
+
+// RailExpanded reports whether the member keeps Home's Oficina rail
+// expanded.
+func RailExpanded(ctx context.Context, db *sql.DB, memberID string) (bool, error) {
+ var on bool
+ err := db.QueryRowContext(ctx, `SELECT rail_expanded FROM members WHERE id = ?`, memberID).Scan(&on)
+ return on, err
+}
+
+// SetRailExpanded keeps the member's Oficina rail expanded, or not.
+func SetRailExpanded(ctx context.Context, db *sql.DB, memberID string, on bool) error {
+ res, err := db.ExecContext(ctx, `UPDATE members SET rail_expanded = ? WHERE id = ?`, on, 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/rail_test.go b/internal/store/rail_test.go
new file mode 100644
index 0000000..31d1e0d
--- /dev/null
+++ b/internal/store/rail_test.go
@@ -0,0 +1,44 @@
+package store
+
+import (
+ "context"
+ "testing"
+)
+
+// A member's Oficina rail starts collapsed; Keep expanded is theirs alone
+// and holds until they collapse it again.
+func TestRailExpanded(t *testing.T) {
+ ctx, db := context.Background(), open(t)
+ if err := Bootstrap(ctx, db, "owner@example.com"); err != nil {
+ t.Fatal(err)
+ }
+ owner, _, err := MemberByEmail(ctx, db, "owner@example.com")
+ if err != nil {
+ t.Fatal(err)
+ }
+ other, _, err := Invite(ctx, db, "maria@example.com")
+ if err != nil {
+ t.Fatal(err)
+ }
+ if on, err := RailExpanded(ctx, db, owner.ID); err != nil || on {
+ t.Fatalf("fresh member: %v, %v; want collapsed", on, err)
+ }
+ if err := SetRailExpanded(ctx, db, owner.ID, true); err != nil {
+ t.Fatal(err)
+ }
+ if on, err := RailExpanded(ctx, db, owner.ID); err != nil || !on {
+ t.Fatalf("after Keep expanded: %v, %v", on, err)
+ }
+ if on, _ := RailExpanded(ctx, db, other.ID); on {
+ t.Fatal("another member's rail expanded too")
+ }
+ if err := SetRailExpanded(ctx, db, owner.ID, false); err != nil {
+ t.Fatal(err)
+ }
+ if on, _ := RailExpanded(ctx, db, owner.ID); on {
+ t.Fatal("Collapse did not hold")
+ }
+ if err := SetRailExpanded(ctx, db, "no-such-member", true); err == nil {
+ t.Fatal("set for a member who isn't there")
+ }
+}
diff --git a/internal/web/app.go b/internal/web/app.go
index 7153779..e135199 100644
--- a/internal/web/app.go
+++ b/internal/web/app.go
@@ -188,6 +188,7 @@ func App(d *db.DB, cfg config.Config, mailer mail.Sender, inst Installer, logger
r.Group(func(r chi.Router) {
r.Use(a.requireMember)
r.Get("/", a.home)
+ r.Post("/rail", a.railSet)
r.Get("/people", a.people)
r.Post("/people", a.invite)
r.Get("/store", a.storePage)
diff --git a/internal/web/home.go b/internal/web/home.go
index ae0ba1a..f5eef60 100644
--- a/internal/web/home.go
+++ b/internal/web/home.go
@@ -39,6 +39,9 @@ type homePage struct {
// Oficina is the team's Oficina apps (BASE_OFICINA_APPS), drawn as a
// rail on a wide screen and as tiles on a phone.
Oficina []oficinaLink
+ // RailExpanded is the member's Keep expanded: the rail lists every app
+ // and ends in Collapse, instead of folding what doesn't fit under More.
+ RailExpanded bool
// Ask is the chat panel, nil with the chat off.
Ask *askView
}
@@ -117,6 +120,13 @@ func (a *app) home(w http.ResponseWriter, r *http.Request) {
for _, o := range a.cfg.OficinaApps {
page.Oficina = append(page.Oficina, oficinaLink{Name: o.Name, Href: o.Origin + "/", Icon: "static/oficina/" + o.ID + ".svg"})
}
+ if len(page.Oficina) > 0 {
+ if page.RailExpanded, err = store.RailExpanded(r.Context(), a.db, me.ID); err != nil {
+ a.logger.Error("home: rail", "err", err)
+ http.Error(w, "unavailable", http.StatusServiceUnavailable)
+ return
+ }
+ }
installedOwn := false
for _, in := range installs {
e, ok := catalog.Get(in.App)
@@ -160,3 +170,24 @@ func (a *app) home(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Cache-Control", "no-store")
a.render(w, "home", page)
}
+
+// railSet is Keep expanded (expanded=1) and Collapse (expanded=0) for Home's
+// Oficina rail: a plain form, so it works without scripts.
+func (a *app) railSet(w http.ResponseWriter, r *http.Request) {
+ me, _ := CurrentMember(r)
+ var on bool
+ switch r.PostFormValue("expanded") {
+ case "1":
+ on = true
+ case "0":
+ default:
+ http.Error(w, "bad request", http.StatusBadRequest)
+ return
+ }
+ if err := store.SetRailExpanded(r.Context(), a.db, me.ID, on); err != nil {
+ a.logger.Error("rail: set", "err", err)
+ http.Error(w, "unavailable", http.StatusServiceUnavailable)
+ return
+ }
+ http.Redirect(w, r, "/", http.StatusSeeOther)
+}
diff --git a/internal/web/templates/home.html b/internal/web/templates/home.html
index c34038d..5beccec 100644
--- a/internal/web/templates/home.html
+++ b/internal/web/templates/home.html
@@ -8,8 +8,20 @@
<a class="me" href="/settings" aria-label="Settings">{{.Initials}}</a>
</div>
<div class="home-cols">
-{{with .Oficina}}<nav class="rail glass" aria-label="Oficina">
-{{range .}}<a class="rail-app" href="{{.Href}}" target="_blank" rel="noopener"><img src="{{asset .Icon}}" alt=""><span>{{.Name}}</span></a>
+{{if .Oficina}}<nav class="rail glass {{if .RailExpanded}}expanded{{else}}collapsed{{end}}" aria-label="Oficina">
+{{range .Oficina}}<a class="rail-app" href="{{.Href}}" target="_blank" rel="noopener"><img src="{{asset .Icon}}" alt=""><span>{{.Name}}</span></a>
+{{end}}{{if .RailExpanded}}<form class="rail-collapse" method="post" action="/rail"><input type="hidden" name="expanded" value="0"><button class="rail-app" type="submit"><i class="glyph" aria-hidden="true"><svg viewBox="0 0 24 24"><path d="M7 14l5-5 5 5"/></svg></i><span>Collapse</span></button></form>
+{{else}}{{/* CSS shows as many apps as fit and turns the last spot into More,
+ whose panel shows the rest: it lists every app and hides the ones the
+ rail already shows. */}}<details class="rail-more"><summary class="rail-app"><i class="glyph" aria-hidden="true"><svg viewBox="0 0 24 24"><path d="M6 12h.01M12 12h.01M18 12h.01"/></svg></i><span>More</span></summary>
+<div class="rail-panel" role="region" aria-label="More Oficina apps">
+<div class="rail-panel-apps">
+{{range .Oficina}}<a class="rail-panel-app" href="{{.Href}}" target="_blank" rel="noopener"><img src="{{asset .Icon}}" alt=""><span>{{.Name}}</span></a>
+{{end}}</div>
+<form method="post" action="/rail"><input type="hidden" name="expanded" value="1"><button class="switch" type="submit" role="switch" aria-checked="false"><span>Keep expanded</span><i aria-hidden="true"></i></button></form>
+</div>
+</details>
+<script type="module" src="{{asset "static/rail.js"}}"></script>
{{end}}</nav>
{{end}}<div class="home-body">
<h2 class="hello">{{.Greeting}}</h2>
diff --git a/internal/webtest/home_test.go b/internal/webtest/home_test.go
index 856d571..a75a820 100644
--- a/internal/webtest/home_test.go
+++ b/internal/webtest/home_test.go
@@ -3,6 +3,7 @@ package webtest
import (
"context"
"database/sql"
+ "net/url"
"regexp"
"strings"
"testing"
@@ -127,7 +128,7 @@ func TestHomeTileUsesRecordedHost(t *testing.T) {
}
var (
- railRE = regexp.MustCompile(`(?s)<nav class="rail glass" aria-label="Oficina">(.*?)</nav>`)
+ railRE = regexp.MustCompile(`(?s)<nav class="rail glass (collapsed|expanded)" aria-label="Oficina">(.*?)</nav>`)
oficinaRE = regexp.MustCompile(`(?s)<section class="oficina" aria-labelledby="oficina-heading">\s*<h3 id="oficina-heading">Oficina</h3>(.*?)</section>`)
appLinkRE = regexp.MustCompile(`<a class="([^"]*)" href="([^"]*)" target="_blank" rel="noopener">`)
appIconRE = regexp.MustCompile(`<img src="(/static/oficina/[a-z]+\.[0-9a-f]+\.svg)" alt="">`)
@@ -157,7 +158,11 @@ func TestHomeListsOficinaApps(t *testing.T) {
if strings.Index(body, `class="oficina"`) > strings.Index(body, `class="dock"`) {
t.Error("the phone's Oficina tiles come after Store, People and Settings")
}
- for _, c := range []struct{ name, html, class string }{{"rail", rail[1], "rail-app"}, {"tiles", tiles[1], "app"}} {
+ railApps, panel, ok := strings.Cut(rail[2], `<details class="rail-more">`)
+ if rail[1] != "collapsed" || !ok {
+ t.Fatalf("rail is %s, More entry found %v:\n%s", rail[1], ok, rail[2])
+ }
+ for _, c := range []struct{ name, html, class string }{{"rail", railApps, "rail-app"}, {"More panel", panel, "rail-panel-app"}, {"tiles", tiles[1], "app"}} {
links := appLinkRE.FindAllStringSubmatch(c.html, -1)
icons := appIconRE.FindAllStringSubmatch(c.html, -1)
labels := appLabelRE.FindAllStringSubmatch(c.html, -1)
@@ -200,3 +205,75 @@ func TestEveryOficinaAppHasAnIcon(t *testing.T) {
}
}
}
+
+var (
+ moreRE = regexp.MustCompile(`(?s)<details class="rail-more"><summary class="rail-app">.*?<span>More</span></summary>\s*<div class="rail-panel" role="region" aria-label="More Oficina apps">(.*?)</div>\s*</details>`)
+ keepRE = regexp.MustCompile(`(?s)<form method="post" action="/rail"><input type="hidden" name="expanded" value="1"><button class="switch" type="submit" role="switch" aria-checked="false"><span>Keep expanded</span>`)
+ collapseRE = regexp.MustCompile(`(?s)<form class="rail-collapse" method="post" action="/rail"><input type="hidden" name="expanded" value="0"><button class="rail-app" type="submit">.*?<span>Collapse</span></button></form>\s*</nav>`)
+)
+
+func newRailApp(t *testing.T) *testApp {
+ t.Helper()
+ a := newAppConfigured(t, func(*sql.DB, config.Config) web.Installer { return noInstaller{} }, time.UTC,
+ func(c *config.Config) { c.OficinaApps = oficinaApps })
+ a.signedInOwner()
+ return a
+}
+
+// The rail starts collapsed: every app is in it, and in a More panel too
+// (CSS shows in each whichever the rail's height leaves over), with the
+// Keep expanded switch, a plain POST form.
+func TestRailMore(t *testing.T) {
+ a := newRailApp(t)
+ body := a.get("/").Body
+ m := moreRE.FindStringSubmatch(body)
+ if m == nil {
+ t.Fatalf("no More entry with its labelled panel:\n%s", body)
+ }
+ if !keepRE.MatchString(m[1]) {
+ t.Errorf("no Keep expanded switch in the panel:\n%s", m[1])
+ }
+ if collapseRE.MatchString(body) {
+ t.Error("a collapsed rail offers Collapse")
+ }
+}
+
+// Keep expanded is the member's, kept on the server: it holds in a new
+// sign-in on another browser, until they collapse the rail again.
+func TestRailKeepExpanded(t *testing.T) {
+ a := newRailApp(t)
+ if r := a.post("/rail", url.Values{"expanded": {"1"}}); r.Code != 303 || r.Location() != "/" {
+ t.Fatalf("Keep expanded: %d %q", r.Code, r.Location())
+ }
+ expanded := func(b *testApp) {
+ t.Helper()
+ body := b.get("/").Body
+ rail := railRE.FindStringSubmatch(body)
+ if rail == nil || rail[1] != "expanded" {
+ t.Fatalf("rail not expanded:\n%s", body)
+ }
+ if strings.Contains(rail[2], "rail-more") || !collapseRE.MatchString(body) {
+ t.Errorf("expanded rail: More shown or no Collapse at the end:\n%s", rail[2])
+ }
+ if n := len(appLinkRE.FindAllString(rail[2], -1)); n != len(oficinaApps) {
+ t.Errorf("expanded rail lists %d apps, want %d", n, len(oficinaApps))
+ }
+ }
+ expanded(a)
+
+ other := a.newBrowser()
+ other.signedInOwner()
+ expanded(other)
+
+ if r := other.post("/rail", url.Values{"expanded": {"0"}}); r.Code != 303 || r.Location() != "/" {
+ t.Fatalf("Collapse: %d %q", r.Code, r.Location())
+ }
+ if rail := railRE.FindStringSubmatch(a.get("/").Body); rail == nil || rail[1] != "collapsed" {
+ t.Fatal("Collapse did not hold for the member's other browser")
+ }
+ for _, bad := range []url.Values{{"expanded": {"yes"}}, {}} {
+ if r := a.post("/rail", bad); r.Code != 400 {
+ t.Errorf("%v: %d, want 400", bad, r.Code)
+ }
+ }
+}