From 2e4039cd70fcebbbf6f6cad9cf350f2b8ea3f778 Mon Sep 17 00:00:00 2001 From: minie4 Date: Mon, 3 Oct 2022 14:28:40 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Replace=20circular=20with=20linear?= =?UTF-8?q?=20loading=20indicator?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.vue | 6 +- src/assets/themes.css | 4 +- src/components/day-carousel.vue | 6 +- src/components/loading-element.vue | 89 ++++++++++++++++++------------ src/store.js | 10 ++++ 5 files changed, 75 insertions(+), 40 deletions(-) diff --git a/src/App.vue b/src/App.vue index d8c5c37..cc8e55a 100644 --- a/src/App.vue +++ b/src/App.vue @@ -4,7 +4,7 @@ import TitleBar from "./components/titlebar-element.vue"; import BottomNavbar from "./components/bottom-navbar.vue"; import DateSelector from "./components/date-selector.vue"; import LoadingElement from "./components/loading-element.vue"; -import { loading, theme } from "./store"; +import { loading, loadingProgress, theme } from "./store"; import { computed, ref } from "vue"; const autoThemes = { true: "dark", false: "light" }; @@ -31,10 +31,10 @@ const isDataView = computed(() => { :class="theme == 'auto' ? `theme-${autoTheme}` : `theme-${theme}`" > - +
- +
diff --git a/src/assets/themes.css b/src/assets/themes.css index 1096af7..5a85f9a 100644 --- a/src/assets/themes.css +++ b/src/assets/themes.css @@ -16,6 +16,7 @@ --bottomnav-active-color: #7ca74b; --bottomnav-shadow: 5px 7px 19px 0px rgba(0, 0, 0, 0.25); --loader-color: #7ca74b; + --loader-error-color: #a54a4a; --substitution-background-change: #095079; --substitution-background-cancellation: #7d2b2d; --substitution-background-addition: #375c1d; @@ -42,7 +43,8 @@ --bottomnav-icon-active-color: #456c47; --bottomnav-active-color: #99b677; --bottomnav-shadow: 5px 7px 19px 0px rgba(0, 0, 0, 0.25); - --loader-color: #7ca74b; + --loader-color: #8bab7c; + --loader-error-color: #db5a5a; --substitution-background-change: #9bb7c7; --substitution-background-cancellation: #e4a7a9; --substitution-background-addition: #b0d396; diff --git a/src/components/day-carousel.vue b/src/components/day-carousel.vue index fc0ab61..3b31d68 100644 --- a/src/components/day-carousel.vue +++ b/src/components/day-carousel.vue @@ -26,7 +26,11 @@ const loadedDates = ref([ // Load left or right date on slide change function slideChange(swiper) { - selectedDate.value = loadedDates.value[swiper.activeIndex]; + // Only trigger data refresh if date is different + const newSelectedDate = loadedDates.value[swiper.activeIndex]; + if (selectedDate.value.getTime() != newSelectedDate.getTime()) + selectedDate.value = newSelectedDate; + const activeSlide = swiper.activeIndex; if (activeSlide == loadedDates.value.length - 1) { const lastDate = loadedDates.value[loadedDates.value.length - 1]; diff --git a/src/components/loading-element.vue b/src/components/loading-element.vue index 6272b5e..47f8197 100644 --- a/src/components/loading-element.vue +++ b/src/components/loading-element.vue @@ -1,54 +1,73 @@ diff --git a/src/store.js b/src/store.js index 1fe6a6e..79fb07c 100644 --- a/src/store.js +++ b/src/store.js @@ -5,6 +5,7 @@ import i18n from "./main"; export const lastRoute = ref(); export const loading = ref(false); +export const loadingProgress = ref(0); export const classFilter = ref(localStorage.getItem("classFilter") || "none"); export const timetableGroups = ref( @@ -45,9 +46,12 @@ if (selectedDay.value == -1) // Load new data if date changes watch(selectedDate, async () => { + loadingProgress.value = 0.1; loading.value = true; await fetchSubstitutions(); + loadingProgress.value = 1 / 2; await fetchHistory(); + loadingProgress.value = 1; loading.value = false; }); @@ -124,16 +128,22 @@ export const possibleTimetableGroups = computed(() => { const baseUrl = import.meta.env.VITE_API_ENDPOINT || "/api"; export async function fetchData() { + loadingProgress.value = 0.1; loading.value = true; const checkResponse = await fetch(`${baseUrl}/check`); if (checkResponse.status != 200) router.push("/login"); + loadingProgress.value = 1 / 5; await fetchClassList(); + loadingProgress.value = 2 / 5; await fetchTimetable(); + loadingProgress.value = 3 / 5; await fetchSubstitutions(); + loadingProgress.value = 4 / 5; await fetchHistory(); + loadingProgress.value = 1; loading.value = false; }