From f243137145103cf4eccc0c1b558127a901ccb354 Mon Sep 17 00:00:00 2001 From: minie4 Date: Sat, 10 Dec 2022 16:10:10 +0100 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Refactor=20frontend?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/favicon.svg | 2 +- src/App.vue | 2 +- src/components/bottom-navbar.vue | 10 +++--- src/components/date-selector.vue | 13 ++++---- src/components/day-carousel.vue | 33 +++++++++++-------- src/components/loading-element.vue | 11 +++++-- src/components/substitution-list.vue | 1 - ...{initial-setup.vue => timetable-setup.vue} | 4 +-- src/store.js | 3 +- src/util.js | 20 ++++++----- src/views/LoginView.vue | 9 +++-- src/views/TimetableView.vue | 2 +- 12 files changed, 64 insertions(+), 46 deletions(-) rename src/components/{initial-setup.vue => timetable-setup.vue} (98%) diff --git a/public/favicon.svg b/public/favicon.svg index 32e3939..21895a9 100644 --- a/public/favicon.svg +++ b/public/favicon.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/src/App.vue b/src/App.vue index cc8e55a..f060725 100644 --- a/src/App.vue +++ b/src/App.vue @@ -37,8 +37,8 @@ const isDataView = computed(() => { + - diff --git a/src/components/bottom-navbar.vue b/src/components/bottom-navbar.vue index 2cc36dc..d907541 100644 --- a/src/components/bottom-navbar.vue +++ b/src/components/bottom-navbar.vue @@ -32,18 +32,16 @@ import { RouterLink } from "vue-router"; .bottomnav { width: calc(90% - 40px); height: 50px; - background-color: var(--bottomnav-color); - border-radius: 10px; + max-width: 800px; + padding: 0px 20px; position: fixed; bottom: 20px; - left: 50%; - transform: translateX(-50%); display: grid; grid-auto-columns: 1fr; grid-auto-flow: column; - padding: 0px 20px; - max-width: 800px; z-index: 100; + border-radius: 10px; + background-color: var(--bottomnav-color); box-shadow: var(--bottomnav-shadow); } diff --git a/src/components/date-selector.vue b/src/components/date-selector.vue index 0aba2bd..02608b0 100644 --- a/src/components/date-selector.vue +++ b/src/components/date-selector.vue @@ -2,6 +2,7 @@ import { selectedDate, selectedDay, changeDay, changeDate } from "../store"; import ArrowIcon from "./icons/arrow-icon.vue"; import dayjs from "dayjs"; +import { getDateSkippingWeekend } from "../util"; const dayNames = [ "days.sunday", @@ -16,15 +17,15 @@ const dayNames = [ diff --git a/src/components/day-carousel.vue b/src/components/day-carousel.vue index c6e0d04..05ac9e4 100644 --- a/src/components/day-carousel.vue +++ b/src/components/day-carousel.vue @@ -3,6 +3,7 @@ import { selectedDate, changeDate, changeDay } from "../store"; import { Swiper, SwiperSlide } from "swiper/vue"; import { Virtual } from "swiper"; import { ref, watch } from "vue"; +import { getDateSkippingWeekend } from "../util"; defineProps({ element: { @@ -26,20 +27,25 @@ const loadedDates = ref([ // Load left or right date on slide change function slideChange(swiper) { + const activeSlide = swiper.activeIndex; // Only trigger data refresh if date is different - const newSelectedDate = loadedDates.value[swiper.activeIndex]; + const newSelectedDate = loadedDates.value[activeSlide]; if (selectedDate.value.getTime() != newSelectedDate.getTime()) selectedDate.value = newSelectedDate; - - const activeSlide = swiper.activeIndex; + // Check if current slide is the last one if (activeSlide == loadedDates.value.length - 1) { - const lastDate = loadedDates.value[loadedDates.value.length - 1]; + // Append next day to loadedDates + const lastDate = loadedDates.value.at(-1); loadedDates.value.push(getDateSkippingWeekend(calculateDate(lastDate, 1))); } } function slideChangeEnd(swiper) { const activeSlide = swiper.activeIndex; + // Check if the current slide is the first one if (activeSlide == 0) { + // Prepend the previous day to loadedDates + // and slide to the next slide without transition + // so the same day as before is shown const lastDate = loadedDates.value[0]; loadedDates.value = [ getDateSkippingWeekend(calculateDate(lastDate, -1)), @@ -48,6 +54,12 @@ function slideChangeEnd(swiper) { swiper.slideTo(activeSlide + 1, 0); } } +// Also check if a day needs to be prepended +// if the user releases the card later because +// a different event is fired for that +function slideResetEnd(swiper) { + slideChangeEnd(swiper); +} // Helper functions function calculateDate(date, offset) { @@ -60,6 +72,8 @@ function slideToDate(date) { const slide = calculateSlide(date); if (slide != -1) swiperElement.value.slideTo(slide); else { + // If the slide is not loaded yet reset + // loaded dates and load that date loadedDates.value = [calculateDate(date, -1), date, calculateDate(date, 1)]; swiperElement.value.slideTo(1, 0); } @@ -76,16 +90,6 @@ watch(changeDay, (change) => { watch(changeDate, (date) => { slideToDate(new Date(date.setUTCHours(0, 0, 0, 0))); }); - -function getDateSkippingWeekend(date) { - var calculatedDate = date; - // Skip weekend - if (calculatedDate.getDay() == 6) - calculatedDate = new Date(calculatedDate.getTime() + 86400000 * 2); - if (calculatedDate.getDay() == 0) - calculatedDate = new Date(calculatedDate.getTime() - 86400000 * 2); - return calculatedDate; -}