Public: anyone can read this; the crew can change it.

Migrated from github.com/Trevato/SO-ARM100

workbenchthis machine

Phone portrait: a bottom tab bar Drive / Queue / Chat (/ Mod for admins) shows one panel at a time (from main at 1142ee6, forge.json untouched) #177

Merged opened this

Check · Review · Land done · Live — Landed; nothing deploys from this branch, so this is the end of its path.

Merged

smith/arm:smith/159-phone-portrait-a-bottom-tab-bar-drive-qu → main 7 commits fork 2 threads · 2 unresolved

  • Merged. smith/159-phone-portrait-a-bottom-tab-bar-drive-qu was merged into main as df67db9.

Review

Sign in to review this change.
7 files changed +142 −4
Software/README.md +9
@@ -293,6 +293,15 @@ real arm when the link dropped comes back as an error; it is not replayed. Chang
293293 stream) are only accepted from the app's own page, so another site can't
294294 drive the arm through it.
295295
296 **On a phone held upright** the sheet's tabs give way to a bottom bar: **Drive**
297 (the view, and the controls on your turn), **Queue**, **Chat**, **Mod** (the
298 owner only) and **Machine**, one panel at a time. The tab is kept in the URL
299 hash (`#drive`, `#queue`, `#chat`, `#mod`, `#machine`); an unknown one, or
300 `#mod` for anyone but the owner, opens Drive. The bar is drawn once its small
301 module (`src/ui/tabs.js`) has loaded; until then, or if it fails to load, the
302 sheet's own tabs stay. STOP is in the status strip above, in no tab. The bar is
303 absent on a wide screen and on a phone on its side.
304
296305 **The Machine tab: the arm, not a magic box.** Anyone watching can open the
297306 **Machine** tab (a column beside the view on a wide screen). It shows, pushed
298307 as it happens with nothing polled:
Software/so101/src/server.test.ts +2
@@ -180,6 +180,8 @@ describe("viewer page", () => {
180180 expect(r.headers.get("content-type")).toBe("text/javascript");
181181 expect(r.headers.get("cache-control")).toContain("immutable");
182182 const version = path!.split("/")[2];
183 const css = await fetch(`${base}/ui/${version}/tabs.css`);
184 expect([css.status, css.headers.get("content-type")]).toEqual([200, "text/css"]);
183185 expect((await fetch(`${base}/ui/${version}/reach.test.ts`)).status).toBe(404);
184186 expect((await fetch(`${base}/ui/${version}/nothing.js`)).status).toBe(404);
185187 expect((await fetch(`${base}/ui/${version}/..%2Fserver.ts`)).status).toBe(404);
Software/so101/src/server.ts +3 −3
@@ -157,8 +157,8 @@ const JAM_WINDOW = 6;
157157 const RESUME_AFTER_DROPS = 20;
158158 const VENDORED = new Set(["three", "urdf-loader"]);
159159 /** A module the page loads from src/ui: plain JavaScript, never its tests. */
160 const isUiModule = (name: string) => /^[a-z][a-z0-9-]*\.js$/.test(name);
161 const MIME: Record<string, string> = { ".js": "text/javascript", ".mjs": "text/javascript", ".json": "application/json", ".urdf": "application/xml", ".stl": "model/stl", ".dae": "model/vnd.collada+xml", ".png": "image/png", ".jpg": "image/jpeg" };
160 const isUiModule = (name: string) => /^[a-z][a-z0-9-]*\.(js|css)$/.test(name);
161 const MIME: Record<string, string> = { ".js": "text/javascript", ".css": "text/css", ".mjs": "text/javascript", ".json": "application/json", ".urdf": "application/xml", ".stl": "model/stl", ".dae": "model/vnd.collada+xml", ".png": "image/png", ".jpg": "image/jpeg" };
162162
163163 export async function startServer(bus: FeetechBus, options: ServerOptions = {}): Promise<RunningServer> {
164164 const ids = options.ids ?? [1, 2, 3, 4, 5, 6];
@@ -694,7 +694,7 @@ export async function startServer(bus: FeetechBus, options: ServerOptions = {}):
694694 if (!path || ![".js", ".mjs", ".json"].includes(extname(path).toLowerCase())) return json(res, 404, { error: "no such vendored file" });
695695 return file(res, path, "max-age=86400");
696696 }
697 const ui = /^\/ui\/[0-9a-f]{12}\/([a-z][a-z0-9-]*\.js)$/.exec(url.pathname);
697 const ui = /^\/ui\/[0-9a-f]{12}\/([a-z][a-z0-9-]*\.(?:js|css))$/.exec(url.pathname);
698698 if (req.method === "GET" && ui) {
699699 if (!isUiModule(ui[1]!) || !existsSync(join(uiDir, ui[1]!))) return json(res, 404, { error: "no such module" });
700700 return file(res, join(uiDir, ui[1]!), "public, max-age=31536000, immutable");
Software/so101/src/ui/tabs.css added +15
@@ -0,0 +1,15 @@
1 /* The phone-portrait bottom tab bar: one panel at a time. Hidden on desktop and in landscape. STOP stays in the strip.
2 Every rule keys on .docked, which the page sets once the bar is drawn: until then the sheet's own tabs are the navigation. */
3 #dock { display: none; }
4 @media (max-width: 640px) and (orientation: portrait) {
5 html #shell.docked { grid-template-rows: minmax(0, var(--view)) auto minmax(0, 1fr) calc(56px + var(--safe-b)); grid-template-areas: "view" "strip" "sheet" "dock"; }
6 .docked #dock { grid-area: dock; display: flex; background: var(--raised); border-top: 1px solid var(--line); padding: 0 calc(var(--pill) + var(--safe-r)) var(--safe-b) var(--safe-l); }
7 #dock button { flex: 1; min-width: 0; min-height: 56px; padding: 0 2px; border: 0; border-radius: 0; background: none; color: var(--dim); font-weight: 600; }
8 #dock button[aria-selected="true"] { color: var(--fg); box-shadow: inset 0 3px 0 var(--blue); }
outdated

Hiding #tabs here removes Machine on a phone in portrait, and removes all navigation until tabs.js has loaded. Scope this to a state the JS sets once the dock exists, and give the dock a Machine tab.

9 .docked #tabs { display: none; }
10 /* Drive: the view, and the controls on your turn. Everything else: the sheet alone. */
11 html #shell.docked[data-panel="drive"]:not(.mayDrive) { grid-template-rows: minmax(0, 1fr) auto 0 calc(56px + var(--safe-b)); }
12 html #shell.docked[data-panel="drive"]:not(.mayDrive) #sheet { display: none; }
13 html #shell.docked:not([data-panel="drive"]) { grid-template-rows: 0 auto minmax(0, 1fr) calc(56px + var(--safe-b)); }
14 #shell.docked:not([data-panel="drive"]) #app { display: none; }
15 }
Software/so101/src/ui/tabs.js added +54
@@ -0,0 +1,54 @@
1 // The phone's bottom tab bar: which tabs a viewer has and which one a hash names. STOP is in no tab.
2 export const SHEET_TAB = { drive: "controls", queue: "queue", chat: "chat", mod: "admin", machine: "machine" };
3
4 /** Queue and Chat need a lobby; Mod is for admins; Machine is for everyone, as in the sheet. */
5 export const tabsFor = ({ mod = false, lobby = true } = {}) =>
6 ["drive", ...(lobby ? ["queue", "chat"] : []), ...(mod ? ["mod"] : []), "machine"].map((id) => ({ id, label: id[0].toUpperCase() + id.slice(1) }));
7
8 /** The tab the hash names, or Drive. */
9 export const tabFromHash = (hash, tabs = tabsFor()) => {
10 const name = String(hash ?? "").replace(/^#/, "").toLowerCase();
11 return tabs.some((t) => t.id === name) ? name : "drive";
12 };
13
14 export const hashFor = (id) => `#${id}`;
15
16 /** The tab an arrow key moves to from the current one (wrapping), or null for any other key. */
17 export const arrow = (ids, current, key) => {
18 const step = { ArrowRight: 1, ArrowLeft: -1 }[key];
19 return step && ids.length ? ids[(ids.indexOf(current) + step + ids.length) % ids.length] : null;
20 };
21
22 /**
23 * The bar on the page: draws the tabs into `dock` as roving-tabindex buttons, each controlling its sheet panel (which it then labels),
24 * and shows the panel the hash names through `showTab`. `who()` says { mod, lobby }.
25 */
26 export function mountDock(dock, shell, showTab, who) {
27 const me = { panel: "drive", sync, go };
28 function go(name, write = false) {
29 me.panel = tabFromHash(hashFor(name), tabsFor(who()));
30 shell.dataset.panel = me.panel;
31 if (write) history.replaceState(null, "", hashFor(me.panel));
32 showTab(SHEET_TAB[me.panel]);
33 for (const b of dock.children) { const on = b.dataset.panel === me.panel; b.setAttribute("aria-selected", String(on)); b.tabIndex = on ? 0 : -1; }
34 }
35 function sync(force) {
36 const tabs = tabsFor(who()), ids = tabs.map((t) => t.id).join();
37 if (!force && dock.dataset.ids === ids) return;
38 dock.dataset.ids = ids;
39 dock.replaceChildren(...tabs.map((t) => {
40 const b = Object.assign(document.createElement("button"), { type: "button", id: `d-${t.id}`, textContent: t.label, onclick: () => go(t.id, true) });
41 const panel = `tab-${SHEET_TAB[t.id]}`;
42 b.setAttribute("role", "tab"); b.setAttribute("aria-controls", panel); b.dataset.panel = t.id;
43 document.getElementById(panel).setAttribute("aria-labelledby", b.id);
44 return b;
45 }));
46 shell.classList.add("docked");
47 go(location.hash);
48 }
49 dock.addEventListener("keydown", (e) => {
50 const n = arrow([...dock.children].map((b) => b.dataset.panel), me.panel, e.key);
51 if (n) { go(n, true); document.getElementById(`d-${n}`).focus(); }
52 });
53 return me;
54 }
Software/so101/src/ui/tabs.test.ts added +43
@@ -0,0 +1,43 @@
1 import { describe, expect, test } from "bun:test";
2 import { arrow, hashFor, SHEET_TAB, tabFromHash, tabsFor } from "./tabs.js";
3
4 describe("the phone's bottom tab bar", () => {
5 test("a plain viewer has Drive, Queue and Chat, and no Mod", () => {
6 expect(tabsFor().map((t) => t.id)).toEqual(["drive", "queue", "chat", "machine"]);
7 expect(tabsFor({ mod: false }).map((t) => t.label)).toEqual(["Drive", "Queue", "Chat", "Machine"]);
8 });
9
10 test("an admin also has Mod before Machine", () => {
11 expect(tabsFor({ mod: true }).map((t) => t.id)).toEqual(["drive", "queue", "chat", "mod", "machine"]);
12 });
13
14 test("without a lobby only Drive and Machine are left", () => {
15 expect(tabsFor({ lobby: false }).map((t) => t.id)).toEqual(["drive", "machine"]);
16 });
17
18 test("the hash picks the tab", () => {
19 expect(tabFromHash("#chat")).toBe("chat");
20 expect(tabFromHash("#Queue")).toBe("queue");
21 expect(tabFromHash(hashFor("mod"), tabsFor({ mod: true }))).toBe("mod");
22 });
23
24 test("an unknown hash falls back to Drive", () => {
25 for (const h of ["", "#", "#nope", "#__proto__", "#chat/../x", undefined, null]) expect(tabFromHash(h as string)).toBe("drive");
26 });
27
28 test("#mod falls back to Drive for a plain viewer", () => {
29 expect(tabFromHash("#mod", tabsFor())).toBe("drive");
30 });
31
32 test("every tab shows a sheet tab", () => {
33 for (const t of tabsFor({ mod: true })) expect(typeof SHEET_TAB[t.id as keyof typeof SHEET_TAB]).toBe("string");
34 });
35
36 test("arrow keys walk the tabs and wrap; other keys do nothing", () => {
37 const ids = ["drive", "queue", "chat"];
38 expect(arrow(ids, "drive", "ArrowRight")).toBe("queue");
39 expect(arrow(ids, "chat", "ArrowRight")).toBe("drive");
40 expect(arrow(ids, "drive", "ArrowLeft")).toBe("chat");
41 expect(arrow(ids, "drive", "Enter")).toBeNull();
42 });
43 });
Software/so101/src/viewer.html +16 −1
@@ -20,6 +20,7 @@
2020 <link rel="modulepreload" href="/ui/__VERSION__/camera-plan.js">
2121 <link rel="modulepreload" href="/ui/__VERSION__/drive.js">
2222 <link rel="modulepreload" href="/ui/__VERSION__/frames.js">
23 <link rel="stylesheet" href="/ui/__VERSION__/tabs.css">
2324 <style>
2425 /* Phone portrait first: the view on top, a status strip with the E-stop under it, a sheet of tabs below that.
2526 Landscape on a phone: the view fills the screen and the strip and the sheet float over it.
@@ -456,6 +457,7 @@
456457 <button role="tab" id="t-machine" data-tab="machine" aria-controls="tab-machine" aria-selected="false">Machine</button>
457458 </nav>
458459 </section>
460 <nav id="dock" role="tablist" aria-label="Panels"></nav>
459461
460462 <div id="metricsPanel" class="panel" hidden>
461463 <button class="close" data-close="metricsPanel">Close</button>
@@ -577,6 +579,16 @@
577579 const i = shown.findIndex((b) => b.dataset.tab === tab);
578580 showTab(shown[(i + (e.key === "ArrowRight" ? 1 : shown.length - 1)) % shown.length].dataset.tab, true);
579581 });
582 // The phone's bottom bar (ui/tabs.js, fetched on a phone in portrait only)
583 const phone = matchMedia("(max-width: 640px) and (orientation: portrait)");
584 let dock = null;
585 async function drawDock(force = false) {
586 shell.classList.toggle("docked", phone.matches && dock !== null);
587 if (!phone.matches) return;
588 try { dock ??= (await import("/ui/__VERSION__/tabs.js")).mountDock($("dock"), shell, showTab, () => ({ mod: isOwner(), lobby: relayed })); } catch { return; }
589 dock.sync(force);
590 }
591 addEventListener("hashchange", () => phone.matches && dock?.go(location.hash)); phone.onchange = () => drawDock(true);
580592 $("sayText").addEventListener("focus", () => { shell.classList.add("typing"); setTimeout(() => (chatBox.scrollTop = chatBox.scrollHeight), 250); });
581593 $("sayText").addEventListener("blur", () => shell.classList.remove("typing"));
582594
@@ -1570,6 +1582,7 @@
15701582 if (why) intent.clear();
15711583 const can = mayDrive() && !why, owner = isOwner();
15721584 $("t-controls").hidden = !mayDrive();
1585 shell.classList.toggle("mayDrive", mayDrive());
15731586 $("t-admin").hidden = !owner;
15741587 $("t-chat").hidden = $("t-queue").hidden = !relayed;
15751588 for (const id of ["joints", "poses", "drive", "reach", "touch", "sticks"]) $(id).inert = !can;
@@ -1586,10 +1599,12 @@
15861599 // Your turn just came: open the controls. It just ended: back to the chat.
15871600 if (mayDrive() !== drove) {
15881601 drove = mayDrive();
1589 if (relayed) showTab(drove ? "controls" : "chat");
1602 if (relayed && phone.matches && dock) dock.go(drove ? "drive" : dock.panel === "drive" ? "chat" : dock.panel, true);
1603 else if (relayed) showTab(drove ? "controls" : "chat");
15901604 if (drove && sideways.matches) setBare(true); // on its side, a turn starts on the thumb sticks
15911605 }
15921606 else if ($(`t-${tab}`).hidden) showTab(tab);
1607 drawDock();
15931608 }
15941609 // The owner's settings: filled from the server whenever they change, unless the owner is typing in the form.
15951610 function fillAdmin(saved) {

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs