mirror of
https://github.com/nfonteyne/octane-website.git
synced 2026-09-03 23:24:48 +02:00
fix: laggy swiping
This commit is contained in:
parent
e368a8681b
commit
4b5b572aa3
1 changed files with 10 additions and 3 deletions
|
|
@ -320,7 +320,7 @@ async function onSuggestionCandidateSelected(candidate) {
|
|||
// ---------- Swipe ("Vote rapide") view ----------
|
||||
|
||||
const VIEW_STORAGE_KEY = 'octane-suggestions-view';
|
||||
let currentView = localStorage.getItem(VIEW_STORAGE_KEY) === 'swipe' ? 'swipe' : 'list';
|
||||
let currentView = localStorage.getItem(VIEW_STORAGE_KEY) === 'list' ? 'list' : 'swipe';
|
||||
let swipeQueue = [];
|
||||
let dragState = null;
|
||||
|
||||
|
|
@ -390,14 +390,21 @@ function renderSwipeStack() {
|
|||
function bindSwipeCardEvents(card, suggestion) {
|
||||
card.addEventListener('pointerdown', (e) => {
|
||||
if (e.pointerType === 'mouse') return;
|
||||
dragState = { id: card.dataset.id, startX: e.clientX, startY: e.clientY, dx: 0, dy: 0 };
|
||||
dragState = { id: card.dataset.id, startX: e.clientX, startY: e.clientY, dx: 0, dy: 0, raf: null };
|
||||
card.style.transition = 'none';
|
||||
card.setPointerCapture(e.pointerId);
|
||||
});
|
||||
card.addEventListener('pointermove', (e) => {
|
||||
if (!dragState || dragState.id !== card.dataset.id) return;
|
||||
dragState.dx = e.clientX - dragState.startX;
|
||||
dragState.dy = e.clientY - dragState.startY;
|
||||
if (dragState.raf) return;
|
||||
dragState.raf = requestAnimationFrame(() => {
|
||||
if (dragState) {
|
||||
applyDragTransform(card, dragState.dx, dragState.dy);
|
||||
dragState.raf = null;
|
||||
}
|
||||
});
|
||||
});
|
||||
const endDrag = (e) => {
|
||||
if (!dragState || dragState.id !== card.dataset.id) return;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue