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 #116

Parked opened this
Closed without merging

smith/arm:smith/113-phone-portrait-a-bottom-tab-bar-drive-qu → main 3 commits fork

  • Closed without merging. Nothing was applied to main.

Review

Sign in to review this change.
6 files changed +76 −5
Software/so101/src/manifest.test.ts +4
@@ -26,3 +26,7 @@ test("the terminal the forge opens on ssh is this package's tty, run from the re
2626 expect(command).toMatch(/^bun run [\w./-]+\.ts$/);
2727 expect(await Bun.file(new URL(`../../../${command.slice("bun run ".length)}`, import.meta.url)).exists()).toBe(true);
2828 });
29
30 test("the health check answers while the arm is unreachable: not /status (503 before the first status)", () => {
31 expect(manifest.app.health).not.toBe("/status");
32 });
Software/so101/src/server.ts +3 −3
@@ -154,8 +154,8 @@ const JAM_WINDOW = 6;
154154 const RESUME_AFTER_DROPS = 20;
155155 const VENDORED = new Set(["three", "urdf-loader"]);
156156 /** A module the page loads from src/ui: plain JavaScript, never its tests. */
157 const isUiModule = (name: string) => /^[a-z][a-z0-9-]*\.js$/.test(name);
158 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" };
157 const isUiModule = (name: string) => /^[a-z][a-z0-9-]*\.(js|css)$/.test(name);
158 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" };
159159
160160 export async function startServer(bus: FeetechBus, options: ServerOptions = {}): Promise<RunningServer> {
161161 const ids = options.ids ?? [1, 2, 3, 4, 5, 6];
@@ -685,7 +685,7 @@ export async function startServer(bus: FeetechBus, options: ServerOptions = {}):
685685 if (!path || ![".js", ".mjs", ".json"].includes(extname(path).toLowerCase())) return json(res, 404, { error: "no such vendored file" });
686686 return file(res, path, "max-age=86400");
687687 }
688 const ui = /^\/ui\/[0-9a-f]{12}\/([a-z][a-z0-9-]*\.js)$/.exec(url.pathname);
688 const ui = /^\/ui\/[0-9a-f]{12}\/([a-z][a-z0-9-]*\.(?:js|css))$/.exec(url.pathname);
689689 if (req.method === "GET" && ui) {
690690 if (!isUiModule(ui[1]!) || !existsSync(join(uiDir, ui[1]!))) return json(res, 404, { error: "no such module" });
691691 return file(res, join(uiDir, ui[1]!), "public, max-age=31536000, immutable");
Software/so101/src/ui/tabs.css added +9
@@ -0,0 +1,9 @@
1 /* The phone-portrait bottom tab bar: Drive · Queue · Chat (· Mod). 56 px plus the home-indicator inset, targets at least 44 px.
2 Wider screens and landscape keep the sheet's own tab strip; the Machine tab lives there only. STOP is in the strip, outside every tab. */
3 @media (max-width: 640px) and (orientation: portrait) {
4 #tabs { min-height: calc(56px + var(--safe-b)); }
5 #tabs button { min-height: 56px; min-width: 44px; }
6 #tabs #t-machine { display: none; }
7 /* the forge pill sits over the bar's right end: keep the labels clear of it, and the last panel's end clear of the bar */
8 #tabs { padding-right: calc(var(--pill) + var(--safe-r)); }
9 }
Software/so101/src/ui/tabs.js added +28
@@ -0,0 +1,28 @@
1 /**
2 * The phone's bottom tab bar as a pure function: which tabs a viewer sees, and which panel a location.hash names.
3 * `panel` is the id suffix of the page's own sheet panel (tab-<panel>). Mod is for the owner and moderators only.
4 */
5
6 export const TABS = [
7 { id: "drive", label: "Drive", panel: "controls" },
8 { id: "queue", label: "Queue", panel: "queue" },
9 { id: "chat", label: "Chat", panel: "chat" },
10 { id: "mod", label: "Mod", panel: "admin", staff: true },
11 ];
12
13 /** The tabs this viewer may open, in bar order. */
14 export function visibleTabs({ staff = false } = {}) {
15 return TABS.filter((t) => !t.staff || staff);
16 }
17
18 /** The tab a hash like "#chat" names; anything unknown, or Mod for a plain viewer, is Drive. */
19 export function tabFromHash(hash, roles = {}) {
20 const id = typeof hash === "string" ? hash.replace(/^#/, "") : "";
21 return (visibleTabs(roles).find((t) => t.id === id) ?? TABS[0]).id;
22 }
23
24 /** The hash that keeps a panel (a sheet panel name) across a reload, or null for a panel the bar does not hold. */
25 export function hashForPanel(panel) {
26 const tab = TABS.find((t) => t.panel === panel);
27 return tab ? `#${tab.id}` : null;
28 }
Software/so101/src/ui/tabs.test.ts added +23
@@ -0,0 +1,23 @@
1 import { expect, test } from "bun:test";
2 import { hashForPanel, tabFromHash, visibleTabs } from "./tabs.js";
3
4 test("a known hash names its tab; an unknown one falls back to Drive", () => {
5 expect(tabFromHash("#chat")).toBe("chat");
6 expect(tabFromHash("#queue")).toBe("queue");
7 expect(tabFromHash("#nonsense")).toBe("drive");
8 expect(tabFromHash("")).toBe("drive");
9 expect(tabFromHash(undefined as unknown as string)).toBe("drive");
10 });
11
12 test("Mod is absent for a plain viewer, and #mod falls back to Drive", () => {
13 expect(visibleTabs().map((t) => t.id)).toEqual(["drive", "queue", "chat"]);
14 expect(visibleTabs({ staff: true }).map((t) => t.id)).toEqual(["drive", "queue", "chat", "mod"]);
15 expect(tabFromHash("#mod")).toBe("drive");
16 expect(tabFromHash("#mod", { staff: true })).toBe("mod");
17 });
18
19 test("a sheet panel maps to its hash; Machine has none", () => {
20 expect(hashForPanel("controls")).toBe("#drive");
21 expect(hashForPanel("admin")).toBe("#mod");
22 expect(hashForPanel("machine")).toBeNull();
23 });
Software/so101/src/viewer.html +9 −2
@@ -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.
@@ -449,8 +450,8 @@
449450 <nav id="tabs" role="tablist" aria-label="Sheet">
450451 <button role="tab" id="t-chat" data-tab="chat" aria-controls="tab-chat" aria-selected="true">Chat<span class="badge" id="unread"></span></button>
451452 <button role="tab" id="t-queue" data-tab="queue" aria-controls="tab-queue" aria-selected="false">Queue<span class="badge" id="waiting"></span></button>
452 <button role="tab" id="t-controls" data-tab="controls" aria-controls="tab-controls" aria-selected="false" hidden>Controls</button>
453 <button role="tab" id="t-admin" data-tab="admin" aria-controls="tab-admin" aria-selected="false" hidden>Admin</button>
453 <button role="tab" id="t-controls" data-tab="controls" aria-controls="tab-controls" aria-selected="false" hidden>Drive</button>
454 <button role="tab" id="t-admin" data-tab="admin" aria-controls="tab-admin" aria-selected="false" hidden>Mod</button>
454455 <button role="tab" id="t-machine" data-tab="machine" aria-controls="tab-machine" aria-selected="false">Machine</button>
455456 </nav>
456457 </section>
@@ -547,12 +548,17 @@
547548 };
548549 $("sheetToggle").onclick = () => setBare(!shell.classList.contains("bare"));
549550 const sideways = matchMedia("(orientation: landscape) and (max-height: 500px)");
551 const { hashForPanel, TABS } = await import("/ui/__VERSION__/tabs.js"); // fetched beside the page, not counted up front
550552 let tab = "chat";
553 /** The tab the address names, opened once its button is there (the Drive and Mod tabs wait for the lobby's word on who you are). */
554 let wanted = TABS.find((t) => `#${t.id}` === location.hash)?.panel ?? null;
551555 /** The Machine tab's panel, once it is loaded (below); here, because leaving any tab closes it. */
552556 const machine = { panel: null };
553557 function showTab(name, focus = false) {
554558 if ($(`t-${name}`).hidden) name = ["controls", "chat", "admin"].find((t) => !$(`t-${t}`).hidden) ?? "chat";
555559 tab = name;
560 const hash = hashForPanel(name);
561 if (hash && location.hash !== hash) history.replaceState(null, "", hash); // a reload keeps the tab
556562 for (const b of $("tabs").querySelectorAll("[role=tab]")) {
557563 const on = b.dataset.tab === name;
558564 b.setAttribute("aria-selected", String(on)); b.tabIndex = on ? 0 : -1;
@@ -1589,6 +1595,7 @@
15891595 if (drove && sideways.matches) setBare(true); // on its side, a turn starts on the thumb sticks
15901596 }
15911597 else if ($(`t-${tab}`).hidden) showTab(tab);
1598 if (wanted) { const w = wanted; wanted = null; if (!$(`t-${w}`).hidden) showTab(w); }
15921599 }
15931600 const serverNow = () => Date.now() + lobby.offset;
15941601 const minutes = (ms) => { const t = Math.max(0, Math.ceil(ms / 1000)); return `${Math.floor(t / 60)}:${String(t % 60).padStart(2, "0")}`; };

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs