char-slop/chordpad.vibed.software
git clone https://git.t4t.associates/char-slop/chordpad.vibed.software
dbf5af8
main
1import type { JSX } from "@char/aftercare/jsx-runtime" ; 2import { project } from "../project/store.ts" ; 3import { watch } from "./dom.tsx" ; 4import { activeTrackId , chordEdit } from "./state.ts" ; 5 6type Hint = [ keys :string [], action :string ]; 7 8const HINTS :Record < string , Hint []> = { 9typing :[ 10[[ "space" ], "next chord" ], 11[[ "enter" ], "done" ], 12[[ "esc" ], "cancel" ], 13], 14chords :[ 15[[ "A–G" , "I–VII" ], "type a chord" ], 16[[ "←→" ], "move" ], 17[[ "↑↓" ], "inversion" ], 18[[ "p" ], "unpin" ], 19[[ "space" ], "play" ], 20], 21notes :[ 22[[ "click" ], "add" ], 23[[ "ctrl click" ], "move cursor" ], 24[[ "shift drag" ], "select" ], 25[[ "alt click" ], "delete" ], 26[[ "↑↓" ], "transpose" ], 27[[ "space" ], "play" ], 28], 29none :[[[ "space" ], "play" ]], 30}; 31 32const render = ([ keys , action ] :Hint ) => ( 33< span class = "hint" > 34{ keys . map ( k => ( 35< kbd >{ k }</ kbd > 36))}{ " " } 37{ action} 38< / span > 39); 40 41/** the few keys that matter for whatever's being edited */ 42export function Hints () :JSX . Element { 43const bar = (< footer class = "hints" / >) as HTMLElement ; 44let shown = "" ; 45watch ( bar , [ activeTrackId , chordEdit , project ], () => { 46const track = project . get (). tracks . find ( t => t . id === activeTrackId . get ()); 47const which = chordEdit . get () ?"typing" :( track ?. kind ?? "none" ); 48if ( which === shown ) return ; 49shown = which ; 50bar . replaceChildren ( ...HINTS [ which ]. map ( render )); 51}); 52return bar ; 53}