Skip to content

Commit

Permalink
Merge pull request 'liam - Issue #5 - swiping left and right to chang…
Browse files Browse the repository at this point in the history
…e dates on mobile' (#10) from liam_a/running-calorie-average:liam into main

Reviewed-on: https://codeberg.org/508_dev/running-calorie-average/pulls/10
Reviewed-by: Caleb Rogers <[email protected]>
  • Loading branch information
Caleb Rogers committed May 28, 2024
2 parents 7060146 + 63defe2 commit cc1aab0
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion src/routes/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
let resetConfirm = 3;
$: if (resetConfirm === 0) {
calorieDateMap.reset();
// Set resetConfirm back to 3 after 1500 milliseconds
Expand Down Expand Up @@ -54,6 +55,26 @@
newDate.setDate(newDate.getDate() + 1);
updateDateQuery(newDate.toDateString());
}
// For swiping to change date
let startX: number;
let endX: number;
function handleSwipe() {
if (startX - endX > 50) {
handleDateForward();
} else if (endX - startX > 50) {
handleDateBack();
}
}
function handleTouchStart(event: TouchEvent) {
startX = event.touches[0].clientX;
}
function handleTouchEnd(event: TouchEvent) {
endX = event.changedTouches[0].clientX;
handleSwipe();
}
</script>

<svelte:head>
Expand All @@ -68,7 +89,10 @@
<button on:click={handleDateBack}>
{'<'}
</button>
<h2>
<h2
on:touchstart={handleTouchStart}
on:touchend={handleTouchEnd}
>
{pathname}
</h2>
<button on:click={handleDateForward}>
Expand Down

0 comments on commit cc1aab0

Please sign in to comment.