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
smith/arm:smith/113-phone-portrait-a-bottom-tab-bar-drive-qu → main 3 commits fork
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 | ||
| 26 | 26 | expect(command).toMatch(/^bun run [\w./-]+\.ts$/); |
| 27 | 27 | expect(await Bun.file(new URL(`../../../${command.slice("bun run ".length)}`, import.meta.url)).exists()).toBe(true); |
| 28 | 28 | }); |
| 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; | ||
| 154 | 154 | const RESUME_AFTER_DROPS = 20; |
| 155 | 155 | const VENDORED = new Set(["three", "urdf-loader"]); |
| 156 | 156 | /** 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" }; | |
| 159 | 159 | |
| 160 | 160 | export async function startServer(bus: FeetechBus, options: ServerOptions = {}): Promise<RunningServer> { |
| 161 | 161 | const ids = options.ids ?? [1, 2, 3, 4, 5, 6]; |
| @@ -685,7 +685,7 @@ export async function startServer(bus: FeetechBus, options: ServerOptions = {}): | ||
| 685 | 685 | if (!path || ![".js", ".mjs", ".json"].includes(extname(path).toLowerCase())) return json(res, 404, { error: "no such vendored file" }); |
| 686 | 686 | return file(res, path, "max-age=86400"); |
| 687 | 687 | } |
| 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); | |
| 689 | 689 | if (req.method === "GET" && ui) { |
| 690 | 690 | if (!isUiModule(ui[1]!) || !existsSync(join(uiDir, ui[1]!))) return json(res, 404, { error: "no such module" }); |
| 691 | 691 | 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()); } | |
| 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() + var()); } | |
| 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 @@ | ||
| 20 | 20 | <link rel="modulepreload" href="/ui/__VERSION__/camera-plan.js"> |
| 21 | 21 | <link rel="modulepreload" href="/ui/__VERSION__/drive.js"> |
| 22 | 22 | <link rel="modulepreload" href="/ui/__VERSION__/frames.js"> |
| 23 | <link rel="stylesheet" href="/ui/__VERSION__/tabs.css"> | |
| 23 | 24 | <style> |
| 24 | 25 | /* Phone portrait first: the view on top, a status strip with the E-stop under it, a sheet of tabs below that. |
| 25 | 26 | Landscape on a phone: the view fills the screen and the strip and the sheet float over it. |
| @@ -449,8 +450,8 @@ | ||
| 449 | 450 | <nav id="tabs" role="tablist" aria-label="Sheet"> |
| 450 | 451 | <button role="tab" id="t-chat" data-tab="chat" aria-controls="tab-chat" aria-selected="true">Chat<span class="badge" id="unread"></span></button> |
| 451 | 452 | <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> | |
| 454 | 455 | <button role="tab" id="t-machine" data-tab="machine" aria-controls="tab-machine" aria-selected="false">Machine</button> |
| 455 | 456 | </nav> |
| 456 | 457 | </section> |
| @@ -547,12 +548,17 @@ | ||
| 547 | 548 | }; |
| 548 | 549 | $("sheetToggle").onclick = () => setBare(!shell.classList.contains("bare")); |
| 549 | 550 | 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 | |
| 550 | 552 | 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; | |
| 551 | 555 | /** The Machine tab's panel, once it is loaded (below); here, because leaving any tab closes it. */ |
| 552 | 556 | const machine = { panel: null }; |
| 553 | 557 | function showTab(name, focus = false) { |
| 554 | 558 | if ($(`t-${name}`).hidden) name = ["controls", "chat", "admin"].find((t) => !$(`t-${t}`).hidden) ?? "chat"; |
| 555 | 559 | tab = name; |
| 560 | const hash = hashForPanel(name); | |
| 561 | if (hash && location.hash !== hash) history.replaceState(null, "", hash); // a reload keeps the tab | |
| 556 | 562 | for (const b of $("tabs").querySelectorAll("[role=tab]")) { |
| 557 | 563 | const on = b.dataset.tab === name; |
| 558 | 564 | b.setAttribute("aria-selected", String(on)); b.tabIndex = on ? 0 : -1; |
| @@ -1589,6 +1595,7 @@ | ||
| 1589 | 1595 | if (drove && sideways.matches) setBare(true); // on its side, a turn starts on the thumb sticks |
| 1590 | 1596 | } |
| 1591 | 1597 | else if ($(`t-${tab}`).hidden) showTab(tab); |
| 1598 | if (wanted) { const w = wanted; wanted = null; if (!$(`t-${w}`).hidden) showTab(w); } | |
| 1592 | 1599 | } |
| 1593 | 1600 | const serverNow = () => Date.now() + lobby.offset; |
| 1594 | 1601 | const minutes = (ms) => { const t = Math.max(0, Math.ceil(ms / 1000)); return `${Math.floor(t / 60)}:${String(t % 60).padStart(2, "0")}`; }; |
new above
offline