Skip to content

Commit 45b23fc

Browse files
authored
feature(frontend): avoid loading skeleton data if pre-existing data is avaiable (SCRUM-293) (#190)
1 parent 17f46f3 commit 45b23fc

File tree

2 files changed

+36
-22
lines changed

2 files changed

+36
-22
lines changed

Frontend/pages/student/dashboard.vue

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
>
2020
<CustomMessage :message="t('onboarding.completed')" type="success"/>
2121
<ActionCard
22-
v-if="matches.length"
22+
v-if="matches"
2323
:button-text="t('dashboard.student.startMatching')"
2424
card-type="primary"
2525
@action-button-clicked="navigate('/student/matching')"
@@ -30,16 +30,16 @@
3030
</h2>
3131
<CardStack :amount="3" @click="navigate('/student/matching')">
3232
<SupervisorCard
33-
:current-capacity="matches[0].availableSpots"
34-
:description="matches[0].bio"
35-
:first-name="matches[0].firstName || ''"
36-
:image="matches[0].profileImage"
37-
:last-name="matches[0].lastName || ''"
38-
:max-capacity="matches[0].totalSpots"
33+
:current-capacity="matches.availableSpots"
34+
:description="matches.bio"
35+
:first-name="matches.firstName || ''"
36+
:image="matches.profileImage"
37+
:last-name="matches.lastName || ''"
38+
:max-capacity="matches.totalSpots"
3939
:similarity-score="
40-
Math.round((matches[0].compatibilityScore as number) * 100)
40+
Math.round((matches.compatibilityScore as number) * 100)
4141
"
42-
:tags="matches[0].tags"
42+
:tags="matches.tags"
4343
name="Hello name"
4444
size="xs"
4545
/>
@@ -172,7 +172,6 @@
172172
</template>
173173

174174
<script lang="ts" setup>
175-
import { ref } from "vue";
176175
import { useUserStore } from "~/stores/useUserStore";
177176
import { useSupervisorStore } from "~/stores/useSupervisorStore";
178177
import type { SupervisorData } from "#shared/types/supervisorInterfaces";
@@ -186,7 +185,13 @@ const userStore = useUserStore();
186185
const supervisorStore = useSupervisorStore();
187186
const studentStore = useStudentStore();
188187
189-
const isLoading = ref(true);
188+
const isLoading = computed(() => {
189+
return supervisorStore.supervisors.length === 0 && acceptedSupervisionRequests.value.length === 0;
190+
});
191+
192+
const matches = computed(() => {
193+
return supervisorStore.supervisors[0]
194+
});
190195
191196
const dashboardState = computed(() => studentStore.dashboardState);
192197
const supervisionRequestsSentByCurrentStudent = computed(() =>
@@ -242,12 +247,9 @@ onMounted(async () => {
242247
userStore.user.id
243248
)) as SupervisorData[];
244249
supervisorStore.setSupervisors(res);
245-
matches.value = res;
246250
}
247251
} catch (error) {
248252
console.error("Error fetching supervision requests or user data:", error);
249-
} finally {
250-
isLoading.value = false;
251253
}
252254
});
253255
@@ -272,8 +274,6 @@ watch(
272274
{ immediate: true }
273275
);
274276
275-
const matches = ref([] as SupervisorData[]);
276-
277277
function navigate(route: string) {
278278
navigateTo(route);
279279
}

Frontend/pages/supervisor/dashboard.vue

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import { ref, watch } from "vue";
33
import { useUserStore } from "~/stores/useUserStore";
44
import type { UserData } from "#shared/types/userInterfaces";
5-
import type { SupervisorData } from "#shared/types/supervisorInterfaces";
5+
import type { SupervisorData, SupervisionRequestsData } from "#shared/types/supervisorInterfaces";
66
import { useSupervisionRequests } from "~/composables/useSupervisionRequests";
77
import { FontAwesomeIcon } from "@fortawesome/vue-fontawesome";
88
import EmptyPagePlaceholder from "~/components/Placeholder/EmptyPagePlaceholder.vue";
@@ -12,10 +12,13 @@ const { user } = storeToRefs(authStore)
1212
const { getUserByEmail } = useUserApi();
1313
const { getSupervisorByUserId } = useSupervisorApi();
1414
const userStore = useUserStore();
15+
const supervisorStore = useSupervisorStore();
1516
16-
const current_user = ref<UserData | null>(null);
17-
const supervisor_data = ref<SupervisorData | null>(null);
1817
18+
const current_user = ref<UserData | null>(null);
19+
const supervisor_data = computed(() => {
20+
return supervisorStore.supervisors[0] || null;
21+
});
1922
const {
2023
data: pendingRequests,
2124
} = useSupervisionRequests("PENDING");
@@ -26,7 +29,7 @@ function navigate(route: string) {
2629
2730
const visibleCount = ref(3);
2831
const visibleRequests = computed(
29-
() => pendingRequests.value?.slice(0, visibleCount.value) ?? []
32+
() => supervisorStore.supervisionRequests?.slice(0, visibleCount.value) ?? []
3033
);
3134
3235
watch(
@@ -41,14 +44,25 @@ watch(
4144
current_user.value = userStore.user;
4245
4346
if (current_user.value?.id) {
44-
supervisor_data.value = (await getSupervisorByUserId(
47+
const data = (await getSupervisorByUserId(
4548
current_user.value.id
4649
)) as SupervisorData;
50+
supervisorStore.setSupervisors([data]);
4751
}
4852
},
4953
{ immediate: true }
5054
);
5155
56+
watch(
57+
pendingRequests,
58+
(newVal) => {
59+
if (newVal) {
60+
supervisorStore.setSupervisionRequests(newVal as SupervisionRequestsData[]);
61+
}
62+
},
63+
{ immediate: true }
64+
);
65+
5266
const { t } = useI18n();
5367
5468
definePageMeta({
@@ -69,7 +83,7 @@ definePageMeta({
6983
<FontAwesomeIcon icon="user-group"/>
7084
{{
7185
// this works, even though the IDE tells you it doesnt. The frontend interface types are not consitent with the backend types. Dont ask why.
72-
supervisor_data?.total_spots - supervisor_data?.available_spots
86+
supervisor_data.total_spots - supervisor_data?.available_spots
7387
}}/{{ supervisor_data?.total_spots }}
7488
</h2>
7589
<p class="text-md">

0 commit comments

Comments
 (0)