Skip to content

Commit

Permalink
Refactor goThroughMoves to make it line up more with repeater; go…
Browse files Browse the repository at this point in the history
…al is to make it easier to combine some of their functionality.
  • Loading branch information
johndoknjas committed Dec 12, 2024
1 parent 5a2b55d commit 966fb86
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions ui/round/src/view/replay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,21 +136,17 @@ const goToPly = (ctrl: RoundController, ply: number) => {
};

const goThroughMoves = (ctrl: RoundController, e: Event) => {
let timeoutId: number | undefined = undefined;
const clearMovesTimeout = () => {
clearTimeout(timeoutId);
};
const targetPly = (e: Event) => parseInt((e.target as HTMLElement).getAttribute('data-ply') || '');
const delay = showMovesDecreasingDelay();
document.addEventListener(e.type === 'touchstart' ? 'touchend' : 'mouseup', () => clearMovesTimeout(), {
once: true,
});
const repeat = () => {
goToPly(ctrl, targetPly(e));
timeoutId = setTimeout(repeat, delay.next().value!);
if (isNaN(targetPly(e))) clearMovesTimeout();
if (isNaN(targetPly(e))) clearTimeout(timeoutId);
};
let timeoutId: number | undefined = undefined;
repeat();
const targetPly = (e: Event) => parseInt((e.target as HTMLElement).getAttribute('data-ply') || '');
const eventName = e.type === 'touchstart' ? 'touchend' : 'mouseup';
document.addEventListener(eventName, () => clearTimeout(timeoutId), { once: true });
};

function renderButtons(ctrl: RoundController) {
Expand Down

0 comments on commit 966fb86

Please sign in to comment.