Skip to content

Commit cc1aab0

Browse files
author
Caleb Rogers
committed
Merge pull request 'liam - Issue #5 - swiping left and right to change 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]>
2 parents 7060146 + 63defe2 commit cc1aab0

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

src/routes/+page.svelte

+25-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
99
let resetConfirm = 3;
1010
11+
1112
$: if (resetConfirm === 0) {
1213
calorieDateMap.reset();
1314
// Set resetConfirm back to 3 after 1500 milliseconds
@@ -54,6 +55,26 @@
5455
newDate.setDate(newDate.getDate() + 1);
5556
updateDateQuery(newDate.toDateString());
5657
}
58+
59+
// For swiping to change date
60+
let startX: number;
61+
let endX: number;
62+
63+
function handleSwipe() {
64+
if (startX - endX > 50) {
65+
handleDateForward();
66+
} else if (endX - startX > 50) {
67+
handleDateBack();
68+
}
69+
}
70+
71+
function handleTouchStart(event: TouchEvent) {
72+
startX = event.touches[0].clientX;
73+
}
74+
function handleTouchEnd(event: TouchEvent) {
75+
endX = event.changedTouches[0].clientX;
76+
handleSwipe();
77+
}
5778
</script>
5879

5980
<svelte:head>
@@ -68,7 +89,10 @@
6889
<button on:click={handleDateBack}>
6990
{'<'}
7091
</button>
71-
<h2>
92+
<h2
93+
on:touchstart={handleTouchStart}
94+
on:touchend={handleTouchEnd}
95+
>
7296
{pathname}
7397
</h2>
7498
<button on:click={handleDateForward}>

0 commit comments

Comments
 (0)