From 7c5dab8cdbb5054cab92d1cbe49d96f5af219f6e Mon Sep 17 00:00:00 2001 From: Pablo Date: Wed, 4 Nov 2026 20:25:24 +0100 Subject: [PATCH] =?UTF-8?q?feat:=20deshacer=20el=20=C3=BAltimo=20swipe=20(?= =?UTF-8?q?#26)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Botón "↶ Deshacer" en la pantalla de swipe (y Ctrl/Cmd+Z) que vuelve a la carta anterior y quita su voto de los "sí" del jugador actual. - Solo dentro del turno: deshabilitado en la primera carta, así que no se pueden tocar votos de otro jugador; votar la última carta cierra el turno. - Ignorado durante la animación de salida. - Nombre accesible "Deshacer: ", anuncio por aria-live y foco en la carta recuperada. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 1 + css/style.css | 2 ++ js/app.js | 25 +++++++++++++++++++++++-- 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 22f754e..ff1d45e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ Formato basado en [Keep a Changelog](https://keepachangelog.com/es-ES/1.1.0/). inputs y cartas; los emojis pasan a ser decorativos y el nombre se muestra siempre en texto (también en "También coincidisteis en" y en el admin); chips del admin usables con teclado; `prefers-reduced-motion`. +- Deshacer el último voto del turno con "↶ Deshacer" o Ctrl+Z (#26). ### Cambiado - Contraste WCAG AA: botones rellenos `#E1472B` → `#C93A1F`, textos diff --git a/css/style.css b/css/style.css index aab8180..5f6853f 100644 --- a/css/style.css +++ b/css/style.css @@ -75,6 +75,8 @@ button { font-family: inherit; } .round-btn.yes { background: #C93A1F; color: #FFF8E7; } .round-btn:active { transform: scale(0.9); } .hint { margin-top: 14px; font-size: 12px; color: rgba(247,237,221,0.62); text-align: center; } +.undo-btn { width: auto; margin-top: 16px; padding: 8px 16px; } +.undo-btn:disabled { opacity: 0.4; cursor: default; } .result-title { font-family: 'Fredoka', sans-serif; font-size: 26px; font-weight: 600; text-align: center; margin-bottom: 4px; } .result-sub { color: rgba(247,237,221,0.55); font-size: 13px; text-align: center; margin-bottom: 22px; } diff --git a/js/app.js b/js/app.js index 8adc441..2b1a7ad 100644 --- a/js/app.js +++ b/js/app.js @@ -165,6 +165,22 @@ function finishCard(liked) { render(); } +// Deshacer el último voto del jugador actual: vuelve a la carta anterior y +// la quita de sus "sí" (si era un "no", no hay nada que quitar). Solo dentro +// del turno: en la primera carta no hay voto propio que deshacer, y votar la +// última carta cierra el turno. +function undoSwipe() { + if (state.stage !== "swipe" || state.animating || state.cardIdx === 0) return; + state.cardIdx -= 1; + const card = state.deck[state.cardIdx]; + const likes = state.likesByPlayer[state.playerIdx]; + const i = likes.indexOf(card.id); + if (i !== -1) likes.splice(i, 1); + state.dragX = 0; state.exitDir = 0; + render(); + announce(`Voto deshecho: ${card.name}`); +} + function triggerSwipe(liked) { if (state.animating || !state.deck[state.cardIdx]) return; state.animating = true; @@ -353,7 +369,9 @@ function renderSwipe() { -
Desliza la carta, usa los botones o las flechas ← (no) y → (sí) del teclado
+ +
Desliza la carta, usa los botones o las flechas ← (no) y → (sí) del teclado. Ctrl+Z deshace.
`; } @@ -509,8 +527,10 @@ function render() { // Teclado en el swipe: ← no, → sí (sin auto-repetición, para no votar // varias cartas por mantener la tecla pulsada). document.addEventListener("keydown", (e) => { - if (state.stage !== "swipe" || e.repeat || e.altKey || e.ctrlKey || e.metaKey || e.shiftKey) return; + if (state.stage !== "swipe" || e.repeat || e.altKey || e.shiftKey) return; if (e.target.closest?.("input, textarea, select")) return; + if ((e.ctrlKey || e.metaKey) && e.key.toLowerCase() === "z") { e.preventDefault(); undoSwipe(); return; } + if (e.ctrlKey || e.metaKey) return; if (e.key === "ArrowRight") { e.preventDefault(); triggerSwipe(true); } else if (e.key === "ArrowLeft") { e.preventDefault(); triggerSwipe(false); } }); @@ -525,6 +545,7 @@ document.getElementById("app").addEventListener("click", (e) => { else if (action === "begin-turn") beginTurn(); else if (action === "swipe-no") triggerSwipe(false); else if (action === "swipe-yes") triggerSwipe(true); + else if (action === "undo") undoSwipe(); else if (action === "start-round2") startRound2(); else if (action === "start-round3") startRound3(); else if (action === "reset") resetAll();