22import { ref , watch } from " vue" ;
33import { useUserStore } from " ~/stores/useUserStore" ;
44import type { UserData } from " #shared/types/userInterfaces" ;
5- import type { SupervisorData } from " #shared/types/supervisorInterfaces" ;
5+ import type { SupervisorData , SupervisionRequestsData } from " #shared/types/supervisorInterfaces" ;
66import { useSupervisionRequests } from " ~/composables/useSupervisionRequests" ;
77import { FontAwesomeIcon } from " @fortawesome/vue-fontawesome" ;
88import EmptyPagePlaceholder from " ~/components/Placeholder/EmptyPagePlaceholder.vue" ;
@@ -12,10 +12,13 @@ const { user } = storeToRefs(authStore)
1212const { getUserByEmail } = useUserApi ();
1313const { getSupervisorByUserId } = useSupervisorApi ();
1414const 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+ });
1922const {
2023 data : pendingRequests,
2124} = useSupervisionRequests (" PENDING" );
@@ -26,7 +29,7 @@ function navigate(route: string) {
2629
2730const visibleCount = ref (3 );
2831const visibleRequests = computed (
29- () => pendingRequests . value ?.slice (0 , visibleCount .value ) ?? []
32+ () => supervisorStore . supervisionRequests ?.slice (0 , visibleCount .value ) ?? []
3033);
3134
3235watch (
@@ -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+
5266const { t } = useI18n ();
5367
5468definePageMeta ({
@@ -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