From 29e12134157252e44d8b1daf939557645e7fa685 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A4ssin?= Date: Tue, 15 Oct 2024 10:49:08 +0200 Subject: [PATCH 1/2] put stundenplan data in usestate to prevent refetching --- pages/stundenplan.vue | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pages/stundenplan.vue b/pages/stundenplan.vue index bab01d9..c0d7793 100644 --- a/pages/stundenplan.vue +++ b/pages/stundenplan.vue @@ -32,8 +32,8 @@ const today = new Date().setHours(0, 0, 0, 0); const page = ref(1); - const groupedByDay = ref({}); - const data = ref([]); + const groupedByDay = useState('groupedByDay', (() => ({}))); + const data = useState('stundenplan', (() => [])); const schedule = computed(() => Object.values(groupedByDay.value)); watch(groupedByDay.value, (newVal) => { @@ -51,6 +51,8 @@ }); onMounted(async () => { + if (data.value.length !== 0) return; + const response = await $fetch( `https://corsproxy.io/?https%3A%2F%2Fselfservice.campus-dual.de%2Froom%2Fjson%3Fuserid%3D${username.value}%26hash%3D${password.value}%26t%3D${Math.floor(Date.now() / 1000)}` ); From cd135d123795381e761106aff5cc1ed4ed76afc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A4ssin?= Date: Tue, 15 Oct 2024 11:09:50 +0200 Subject: [PATCH 2/2] add loading state to table --- pages/stundenplan.vue | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pages/stundenplan.vue b/pages/stundenplan.vue index c0d7793..60938b8 100644 --- a/pages/stundenplan.vue +++ b/pages/stundenplan.vue @@ -17,7 +17,7 @@ Zurück zu Heute - + @@ -36,6 +36,8 @@ const data = useState('stundenplan', (() => [])); const schedule = computed(() => Object.values(groupedByDay.value)); + const hasLoaded = ref(false); + watch(groupedByDay.value, (newVal) => { const todayIndex = Object.keys(newVal).indexOf(today.toString()); if (todayIndex !== -1) { @@ -73,6 +75,8 @@ Bemerkungen: item["remarks"] || "---", }); }); + + hasLoaded.value = true; }); function logout() {