Feat: swipe gauche/droite sur Play mobile
All checks were successful
Deploy / Deploy to Production (push) Successful in 19s

Même logique que les touches fléchées : navigation entre jeux,
aux limites passage à la slide précédente/suivante via slideTo.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
isUnknown 2026-03-13 09:31:43 +01:00
parent 44912c1d2f
commit 773be2840c

View file

@ -1,6 +1,7 @@
<script> <script>
import { onMount } from 'svelte' import { onMount } from 'svelte'
import { slides } from '@state/slides.svelte' import { slides } from '@state/slides.svelte'
import { slideTo } from '@router'
import ResponsivePicture from '@components/ui/ResponsivePicture.svelte' import ResponsivePicture from '@components/ui/ResponsivePicture.svelte'
import { t } from '@i18n' import { t } from '@i18n'
@ -87,6 +88,41 @@
} }
} }
// --- Touch (mobile) ---
// Même logique que le clavier : navigation entre jeux en priorité,
// aux limites on laisse passer vers la slide précédente/suivante.
const TOUCH_THRESHOLD = 50
let touchStartX = 0
function onTouchStart(e) {
if (!isActive) return
touchStartX = e.touches[0].clientX
}
function onTouchEnd(e) {
if (!isActive) return
const deltaX = touchStartX - e.changedTouches[0].clientX
if (Math.abs(deltaX) < TOUCH_THRESHOLD) return
if (deltaX > 0) {
// Swipe gauche → jeu suivant, ou slide suivante si fin de liste
if (currentIndex < games.length - 1) {
selectGame(currentIndex + 1)
} else {
const next = slides.all[slides.activeIndex + 1]
if (next) slideTo(next.path)
}
} else {
// Swipe droite → jeu précédent, ou slide précédente si début de liste
if (currentIndex > 0) {
selectGame(currentIndex - 1)
} else {
const prev = slides.all[slides.activeIndex - 1]
if (prev) slideTo(prev.path)
}
}
}
// Réinitialisation quand on quitte la slide // Réinitialisation quand on quitte la slide
$effect(() => { $effect(() => {
if (!isActive) { if (!isActive) {
@ -103,8 +139,12 @@
onMount(() => { onMount(() => {
window.addEventListener('keydown', onKeyDown, { capture: true }) window.addEventListener('keydown', onKeyDown, { capture: true })
window.addEventListener('touchstart', onTouchStart, { capture: true, passive: true })
window.addEventListener('touchend', onTouchEnd, { capture: true, passive: true })
return () => { return () => {
window.removeEventListener('keydown', onKeyDown, { capture: true }) window.removeEventListener('keydown', onKeyDown, { capture: true })
window.removeEventListener('touchstart', onTouchStart, { capture: true })
window.removeEventListener('touchend', onTouchEnd, { capture: true })
clearTimeout(t1) clearTimeout(t1)
clearTimeout(t2) clearTimeout(t2)
clearTimeout(t3) clearTimeout(t3)
@ -425,7 +465,6 @@
text-align: center; text-align: center;
} }
.play-carousel-item.active button img,
.play-carousel-item.active button :global(picture img) { .play-carousel-item.active button :global(picture img) {
border: 4px solid var(--color-primary); border: 4px solid var(--color-primary);
border-radius: 25%; border-radius: 25%;
@ -454,6 +493,13 @@
.play-carousel { .play-carousel {
grid-area: 14/4 / span 3 / span 13; grid-area: 14/4 / span 3 / span 13;
} }
.play-carousel-item :global(img) {
width: clamp(70px, 18.41vw, 355px);
}
.play-carousel-item.active :global(img) {
width: clamp(90px, 18.41vw, 355px);
}
} }
/* Reduced motion */ /* Reduced motion */