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,4 +1,11 @@
import { classFilter } from "./store";
import {
classFilter,
fetchSubstitutions,
fetchHistory,
loading,
selectedDate,
} from "./store";
import dayjs from "dayjs";
export function getSubstitutionText(substitution) {
const includeClass = !classFilter.value || classFilter.value == "none";
@ -22,3 +29,23 @@ export function getSubstitutionColor(substitution) {
return "background-color: var(--substitution-background-cancellation);";
}
}
export function nextDay() {
var newDate = dayjs(selectedDate.value).add(1, "day");
// Skip weekend
if (newDate.day() == 6) newDate = newDate.add(2, "day");
changeDate(newDate);
}
export function previousDay() {
var newDate = dayjs(selectedDate.value).subtract(1, "day");
// Skip weekend
if (newDate.day() == 0) newDate = newDate.subtract(2, "day");
changeDate(newDate);
}
export 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;
}