fix(captures+chord): Stop button stops, ChordPicker accepts shorter chords

Two unrelated correctness bugs caught in PR review:

- The Play As "Stop" button was wired to handlePlayAs() unconditionally, so clicking it during playback kicked a fresh generation instead of halting. Now pauses the player when the click came from the main button while playbackState is 'playing'. Picking a different voice from the dropdown still kicks a new generation as before.
- ChordPicker tracked the peak set of held keys but seeded the peak from initialKeys, so a user who opened the picker with a 3-key chord saved couldn't replace it with a 2-key chord — the candidate length never beat the seed. The peak now resets on the first press of a fresh sequence (when no keys were held immediately prior), then grows monotonically within that hold.
This commit is contained in:
Jamie Pine
2026-04-24 20:35:17 -07:00
parent 7ad91f5767
commit 5f62a0ed1b
2 changed files with 12 additions and 3 deletions
@@ -154,6 +154,8 @@ export function CapturesTab() {
const playerIsPlaying = usePlayerStore((s) => s.isPlaying);
const isPlayerVisible = !!audioUrl;
const setIsPlaying = usePlayerStore((s) => s.setIsPlaying);
const addPendingGeneration = useGenerationStore((s) => s.addPendingGeneration);
const pendingGenerationIds = useGenerationStore((s) => s.pendingGenerationIds);
@@ -410,6 +412,12 @@ export function CapturesTab() {
const handlePlayAs = (voice?: VoiceProfileResponse) => {
if (!selected) return;
// Stop the current playback when the button is in its 'playing' state
// and the user clicked the main button without picking a new voice.
if (!voice && playbackState === 'playing') {
setIsPlaying(false);
return;
}
const target = voice ?? playAsVoice;
if (!target) {
toast({
@@ -95,11 +95,12 @@ export function ChordPicker({
if (prev.has(canonical)) return prev;
const next = new Set(prev);
next.add(canonical);
// Update peak whenever the live set grows. Comparing against
// the captured chord (which may be the previous saved value)
// would lose the user's first new keypress.
setCaptured((prevCaptured) => {
const candidate = sortChordKeys(Array.from(next));
// First key in a fresh sequence replaces the peak — otherwise a
// user trying to swap a longer saved chord for a shorter one is
// stuck because their candidate never beats the seed length.
if (prev.size === 0) return candidate;
return candidate.length >= prevCaptured.length ? candidate : prevCaptured;
});
return next;