A truly modular keyboard
C
Revert "app: a button on chained Keybits to move them to the spot they're really in"
Nathan6039864ac7ac
diff --git a/app/src/renderer/src/components/Board.tsx b/app/src/renderer/src/components/Board.tsxindex 2b1d1d5..b947616 100644--- a/app/src/renderer/src/components/Board.tsx+++ b/app/src/renderer/src/components/Board.tsx@@ -1,5 +1,5 @@import clsx from 'clsx';-import { ArrowLeftRight, Move } from 'lucide-react';+import { ArrowLeftRight } from 'lucide-react';import { useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react';import { actionLabel, activeProfile, demo, entryOf, keyName, openAssign } from '../controller.ts';import { bounds, layout, otherSide, type Placed } from '../lib/layout.ts';@@ -13,14 +13,9 @@ const MAX_H = 320;const PAD = 16;/** Where the user put Keybits that could be on the left or the top, by UID. */const PREFER_KEY = 'board-side';-/** Which spot the user picked for each chained Keybit, by UID. */-const PICK_KEY = 'board-pick';-function load<T>(name: string): Record<string, T> {- try { return JSON.parse(localStorage.getItem(name) || '{}'); } catch { return {}; }-}-function save(name: string, value: object) {- try { localStorage.setItem(name, JSON.stringify(value)); } catch { /* only a convenience */ }+function loadPrefer(): Record<string, Side> {+ try { return JSON.parse(localStorage.getItem(PREFER_KEY) || '{}'); } catch { return {}; }}/**@@ -35,21 +30,15 @@ export function Board() {useApp((s) => s.store); // labels follow the active profileconst isDemo = transport === 'demo';- const [prefer, setPrefer] = useState(() => load<Side>(PREFER_KEY));- const [pick, setPick] = useState(() => load<number>(PICK_KEY));+ const [prefer, setPrefer] = useState(loadPrefer);const flip = (uid: string, now: Side) => {const to = otherSide(now);if (!to) return;const next = { ...prefer, [uid]: to };setPrefer(next);- save(PREFER_KEY, next);- };- const move = (uid: string) => {- const next = { ...pick, [uid]: (pick[uid] ?? 0) + 1 };- setPick(next);- save(PICK_KEY, next);+ try { localStorage.setItem(PREFER_KEY, JSON.stringify(next)); } catch { /* only a convenience */ }};- const placed = useMemo(() => layout(keys, sides, prefer, pick), [keys, sides, prefer, pick]);+ const placed = useMemo(() => layout(keys, sides, prefer), [keys, sides, prefer]);// Keep what just left on screen long enough to pop out.const [leaving, setLeaving] = useState<Placed[]>([]);@@ -123,24 +112,6 @@ export function Board() {);};- /** A chained Keybit's spot is a guess, so it gets a button to try the next spot. */- const mover = (p: Placed) => {- if (p.kind !== 'keybit' || !p.estimated || !p.uid) return null;- return (- <button- key={`move-${p.id}`}- type="button"- title="Not here? Move it to the next spot next to the Keybit it's attached to"- aria-label="Move to the next spot"- onClick={() => move(p.uid!)}- style={{ left: p.x - b.x + p.w - 26, top: p.y - b.y + 4 }}- className="absolute grid size-[22px] place-items-center rounded-md text-muted hover:bg-line hover:text-fg motion-safe:transition-[left,top] motion-safe:duration-300"- >- <Move size={13} />- </button>- );- };-/** A Keybit that could be on the left or the top gets a button to swap it. */const flipper = (p: Placed) => {const k = p.uid ? keys[p.uid] : undefined;@@ -175,7 +146,6 @@ export function Board() {{placed.map((p) => tile(p, false))}{leaving.map((p) => tile(p, true))}{placed.map(flipper)}- {placed.map(mover)}</div></div>{isDemo && <p className="text-xs text-muted">Demo: click a side to attach or remove a Keybit.</p>}diff --git a/app/src/renderer/src/lib/layout.ts b/app/src/renderer/src/lib/layout.tsindex ee9902d..e897e93 100644--- a/app/src/renderer/src/lib/layout.ts+++ b/app/src/renderer/src/lib/layout.ts@@ -63,8 +63,6 @@ export function layout(sides: Partial<Record<Side, boolean>>,/** The side the user put an L/T Keybit on, by UID. */prefer: Record<string, Side> = {},- /** For chained Keybits, which of the possible cells the user picked, by UID. */- pick: Record<string, number> = {},): Placed[] {const cells = new Map<string, string>([[key([0, 0]), 'keyword']]);const at: Record<string, Cell> = {};@@ -106,10 +104,9 @@ export function layout(}).length;const straight = (c: Cell) => c[0] - from[0] === out[0] && c[1] - from[1] === out[1];free.sort((a, b) => touching(b) - touching(a) || Number(straight(b)) - Number(straight(a)));- const c = free[(pick[uid] ?? 0) % free.length];- at[uid] = c;- cells.set(key(c), uid);- hop[`${k.via}:${k.depth}`] ??= c;+ at[uid] = free[0];+ cells.set(key(free[0]), uid);+ hop[`${k.via}:${k.depth}`] ??= free[0];}const px = ([x, y]: Cell) => ({ x: x * STEP, y: y * STEP, w: TILE, h: TILE });