Add swipe gestures for changing days

This commit is contained in:
2022-08-21 23:35:02 +02:00
parent 1439bfb056
commit 198dee45d3
6 changed files with 68 additions and 40 deletions

View File

@ -1,13 +1,8 @@
<script setup>
import {
selectedDate,
selectedDay,
fetchSubstitutions,
fetchHistory,
loading,
} from "../store";
import dayjs from "dayjs";
import { selectedDate, selectedDay } from "../store";
import ArrowIcon from "./icons/arrow-icon.vue";
import dayjs from "dayjs";
import { changeDate, previousDay, nextDay } from "../util";
const dayNames = [
"days.sunday",
@ -18,26 +13,6 @@ const dayNames = [
"days.friday",
"days.saturday",
];
function nextDay() {
var newDate = dayjs(selectedDate.value).add(1, "day");
// Skip weekend
if (newDate.day() == 6) newDate = newDate.add(2, "day");
changeDate(newDate);
}
function previousDay() {
var newDate = dayjs(selectedDate.value).subtract(1, "day");
// Skip weekend
if (newDate.day() == 0) newDate = newDate.subtract(2, "day");
changeDate(newDate);
}
async function changeDate(newDate) {
selectedDate.value = new Date(newDate.toDate().setUTCHours(0, 0, 0, 0));
loading.value = true;
await fetchSubstitutions();
await fetchHistory();
loading.value = false;
}
</script>
<template>