feat: add key 3=Good 4=Easy in review; form-q4 support
Some checks failed
CI / Lint & Test (push) Has been cancelled
Deploy Status Page / Build & Deploy (push) Has been cancelled

This commit is contained in:
viktorvsk 2026-04-23 04:52:59 +00:00
parent 3733e8c9de
commit 79d244fe2a

View File

@ -10,6 +10,7 @@ import { Controller } from "@hotwired/stimulus"
// id="form-left" — learning / forgot // id="form-left" — learning / forgot
// id="form-skip" — skip (filter only) // id="form-skip" — skip (filter only)
// id="form-q3" — hard (review only) // id="form-q3" — hard (review only)
// id="form-q4" — good (review only)
export default class extends Controller { export default class extends Controller {
static targets = ["card"] static targets = ["card"]
@ -28,7 +29,7 @@ export default class extends Controller {
document.removeEventListener("keydown", this._keydown) document.removeEventListener("keydown", this._keydown)
} }
// ── Keyboard ────────────────────────────────────────────────────────────── // ── Keyboard ────────────────────────────────────────────────────────────────
handleKeydown(e) { handleKeydown(e) {
if (this.animating) return if (this.animating) return
@ -65,13 +66,17 @@ export default class extends Controller {
this.slideAndSubmit("slide-up", "form-q3") this.slideAndSubmit("slide-up", "form-q3")
break break
case "3": case "3":
e.preventDefault()
this.slideAndSubmit("slide-up", "form-q4")
break
case "4":
e.preventDefault() e.preventDefault()
this.slideAndSubmit("slide-right", "form-right") this.slideAndSubmit("slide-right", "form-right")
break break
} }
} }
// ── Touch / swipe ───────────────────────────────────────────────────────── // ── Touch / swipe ───────────────────────────────────────────────────────────
touchstart(e) { touchstart(e) {
const t = e.changedTouches[0] const t = e.changedTouches[0]
@ -85,10 +90,9 @@ export default class extends Controller {
const dx = t.clientX - this.touchStartX const dx = t.clientX - this.touchStartX
const dy = t.clientY - this.touchStartY const dy = t.clientY - this.touchStartY
// Small movement = tap, handled by click -> flip
if (Math.abs(dx) < 20 && Math.abs(dy) < 20) return if (Math.abs(dx) < 20 && Math.abs(dy) < 20) return
e.preventDefault() // prevent the click event that follows e.preventDefault()
if (Math.abs(dx) >= Math.abs(dy) && Math.abs(dx) > 40) { if (Math.abs(dx) >= Math.abs(dy) && Math.abs(dx) > 40) {
dx > 0 dx > 0
@ -97,7 +101,7 @@ export default class extends Controller {
} }
} }
// ── Card flip ───────────────────────────────────────────────────────────── // ── Card flip ───────────────────────────────────────────────────────────────
flip(e) { flip(e) {
if (e) e.stopPropagation() if (e) e.stopPropagation()
@ -105,7 +109,7 @@ export default class extends Controller {
this.cardTarget.classList.toggle("is-flipped", this.flipped) this.cardTarget.classList.toggle("is-flipped", this.flipped)
} }
// ── Form submission ─────────────────────────────────────────────────────── // ── Form submission ─────────────────────────────────────────────────────────
slideAndSubmit(animClass, formId) { slideAndSubmit(animClass, formId) {
this.animating = true this.animating = true
@ -116,7 +120,6 @@ export default class extends Controller {
if (form) { if (form) {
form.requestSubmit() form.requestSubmit()
} else { } else {
// form not present on this page variant — ignore silently
this.animating = false this.animating = false
this.cardTarget.classList.remove(animClass) this.cardTarget.classList.remove(animClass)
} }