feat: zie klasgenoten bij klikken op members
This commit is contained in:
parent
0a6a956642
commit
75d74584aa
1 changed files with 30 additions and 17 deletions
|
@ -1,13 +1,16 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { useI18n } from "vue-i18n";
|
import { useI18n } from "vue-i18n";
|
||||||
import authState from "@/services/auth/auth-service.ts";
|
import authState from "@/services/auth/auth-service.ts";
|
||||||
import { computed, onMounted, ref, type ComputedRef } from "vue";
|
import { computed, onMounted, ref, watch, watchEffect, type ComputedRef } from "vue";
|
||||||
import { validate, version } from "uuid";
|
import { validate, version } from "uuid";
|
||||||
import type { TeacherDTO } from "@dwengo-1/common/interfaces/teacher";
|
import type { TeacherDTO } from "@dwengo-1/common/interfaces/teacher";
|
||||||
import type { ClassDTO } from "@dwengo-1/common/interfaces/class";
|
import type { ClassDTO } from "@dwengo-1/common/interfaces/class";
|
||||||
import { useStudentClassesQuery } from "@/queries/students";
|
import { useStudentClassesQuery, useStudentQuery } from "@/queries/students";
|
||||||
|
import type { StudentDTO } from "@dwengo-1/common/interfaces/student";
|
||||||
|
import { StudentController } from "@/controllers/students";
|
||||||
|
|
||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
|
const studentController: StudentController = new StudentController();
|
||||||
|
|
||||||
type Invitation = {
|
type Invitation = {
|
||||||
id: string;
|
id: string;
|
||||||
|
@ -16,16 +19,16 @@
|
||||||
receiver: TeacherDTO;
|
receiver: TeacherDTO;
|
||||||
};
|
};
|
||||||
|
|
||||||
const classes : ComputedRef<ClassDTO[]> = computed(() => {
|
const classes: ComputedRef<ClassDTO[]> = computed(() => {
|
||||||
const response = classesResponse.value;
|
const response = classesResponse.value;
|
||||||
let result : ClassDTO[] = []
|
let result: ClassDTO[] = [];
|
||||||
if (!classesResponse.value){
|
if (!classesResponse.value) {
|
||||||
return result
|
return result;
|
||||||
} else {
|
} else {
|
||||||
if (classesResponse.value.classes.length === 0) {
|
if (classesResponse.value.classes.length === 0) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
if (typeof classesResponse.value.classes[0] === 'string'){
|
if (typeof classesResponse.value.classes[0] === "string") {
|
||||||
for (const classid of classesResponse.value.classes) {
|
for (const classid of classesResponse.value.classes) {
|
||||||
// TODO when class queries are ready
|
// TODO when class queries are ready
|
||||||
}
|
}
|
||||||
|
@ -35,7 +38,6 @@
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
const username = ref<string | undefined>(undefined);
|
const username = ref<string | undefined>(undefined);
|
||||||
|
|
||||||
const { data: classesResponse, isLoading, error } = useStudentClassesQuery(username);
|
const { data: classesResponse, isLoading, error } = useStudentClassesQuery(username);
|
||||||
|
@ -79,19 +81,30 @@
|
||||||
const dialog = ref(false);
|
const dialog = ref(false);
|
||||||
|
|
||||||
// list of students in the selected class
|
// list of students in the selected class
|
||||||
const students = ref<Array<string>>([]);
|
const students = ref<Array<StudentDTO>>([]);
|
||||||
|
|
||||||
// selected class itself
|
// selected class itself
|
||||||
const selectedClass = ref<ClassDTO | null>(null);
|
const selectedClass = ref<ClassDTO | null>(null);
|
||||||
|
|
||||||
// function to display all members of a class
|
// function to display all members of a class
|
||||||
function openDialog(c: ClassDTO) {
|
async function openDialog(c: ClassDTO) {
|
||||||
selectedClass.value = c;
|
selectedClass.value = c;
|
||||||
if (selectedClass.value !== undefined) {
|
|
||||||
// students.value = selectedClass.value.students.map((student) => `${student.firstName} ${student.lastName}`);
|
// clear previous value
|
||||||
students.value = [];
|
students.value = [];
|
||||||
dialog.value = true;
|
dialog.value = true;
|
||||||
}
|
|
||||||
|
const studentDTOs: (StudentDTO | null)[] = await Promise.all(
|
||||||
|
c.students.map(async (uid) => {
|
||||||
|
try {
|
||||||
|
const res = await studentController.getByUsername(uid);
|
||||||
|
return res.student;
|
||||||
|
} catch (e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
students.value = studentDTOs.filter(Boolean) as StudentDTO[];
|
||||||
}
|
}
|
||||||
|
|
||||||
// function to handle a accepted invitation request
|
// function to handle a accepted invitation request
|
||||||
|
@ -352,9 +365,9 @@
|
||||||
<ul>
|
<ul>
|
||||||
<li
|
<li
|
||||||
v-for="student in students"
|
v-for="student in students"
|
||||||
:key="student"
|
:key="student.username"
|
||||||
>
|
>
|
||||||
{{ student }}
|
{{ student.firstName + " " + student.lastName }}
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</v-card-text>
|
</v-card-text>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue