Skip to content

Commit

Permalink
Merge pull request #200 from SELab-2/isTeacherChanges
Browse files Browse the repository at this point in the history
Implement isTeacher correctly
  • Loading branch information
masinnae authored May 15, 2024
2 parents 2272979 + ba316a1 commit 6d56e63
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 11 deletions.
5 changes: 2 additions & 3 deletions frontend/src/components/buttons/GroupButtons.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@ const props = defineProps<{
project: Project;
user: User;
amountOfMembers: number;
isTeacher: boolean;
}>();
const { group, project, user, amountOfMembers } = toRefs(props);
const { group, project, user, amountOfMembers, isTeacher } = toRefs(props);
const canJoinGroup = computed(() => {
return (
Expand All @@ -45,8 +46,6 @@ const canLeaveGroup = computed(() => {
return project.value.capacity !== 1 && isUserInGroup.value && !isTeacher.value;
});
const isTeacher = computed(() => user.value.is_teacher || false);
const isUserInGroup = computed(() => {
return group.value.members.some((member) => member.uid === user.value.uid);
});
Expand Down
4 changes: 3 additions & 1 deletion frontend/src/components/home/cards/GroupCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
:group="group"
:project="project"
:user="user"
:isTeacher="isTeacher"
/>
</v-col>
</v-row>
Expand All @@ -32,9 +33,10 @@ const props = defineProps<{
group: Group;
project: Project;
user: User;
isTeacher: boolean;
}>();
const { group, project, user } = toRefs(props);
const { group, project, user, isTeacher } = toRefs(props);
const amountOfMembers = computed(() => {
return group.value.members.length;
Expand Down
26 changes: 23 additions & 3 deletions frontend/src/views/GroupView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
:group="group!"
:project="project!"
:user="user!"
:isTeacher="isTeacher!"
/>
</v-card-actions>
</v-card>
Expand All @@ -53,6 +54,7 @@ import { useGroupQuery, useRemoveUserFromGroupMutation } from "@/queries/Group";
import { useProjectQuery } from "@/queries/Project";
import { useUserQuery } from "@/queries/User";
import GroupButtons from "@/components/buttons/GroupButtons.vue";
import { useSubjectInstructorsQuery } from "@/queries/Subject";
const props = defineProps<{
groupId: number;
Expand All @@ -68,14 +70,32 @@ const {
isError: isErrorProject,
} = useProjectQuery(computed(() => group.value?.project_id));
const {
data: instructors,
isLoading: isLoadingInstructors,
isError: isErrorInstructors,
} = useSubjectInstructorsQuery(computed(() => project.value?.subject_id));
const { data: user, isLoading: isLoadingUser, isError: isErrorUser } = useUserQuery(null);
const isLoading = computed(
() => isLoadingGroup.value || isLoadingProject.value || isLoadingUser.value
() =>
isLoadingGroup.value ||
isLoadingProject.value ||
isLoadingUser.value ||
isLoadingInstructors.value
);
const isError = computed(
() =>
isErrorGroup.value || isErrorProject.value || isErrorUser.value || isErrorInstructors.value
);
const isError = computed(() => isErrorGroup.value || isErrorProject.value || isErrorUser.value);
const isTeacher = computed(() => user.value?.is_teacher || false);
const isTeacher = computed(() => {
if (!user.value || !instructors.value) {
return false;
}
return instructors.value.some((instructor) => instructor.uid === user.value.uid);
});
const amountOfMembers = computed(() => {
if (!group.value) return 0;
Expand Down
26 changes: 22 additions & 4 deletions frontend/src/views/GroupsView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
:project="project!"
:group="group"
:user="user!"
:isTeacher="isTeacher!"
class="group-card"
/>
</div>
Expand All @@ -37,7 +38,7 @@ import { useProjectQuery } from "@/queries/Project";
import GroupCard from "@/components/home/cards/GroupCard.vue";
import { useUserQuery } from "@/queries/User";
import { type GroupForm } from "@/models/Group";
import { useSubjectStudentsQuery } from "@/queries/Subject";
import { useSubjectInstructorsQuery, useSubjectStudentsQuery } from "@/queries/Subject";
import AllstudentsDialog from "@/components/AllstudentsDialog.vue";
const props = defineProps<{
Expand Down Expand Up @@ -66,19 +67,36 @@ const {
isError: isUsersError,
} = useSubjectStudentsQuery(computed(() => project.value?.subject_id));
const {
data: instructors,
isLoading: isLoadingInstructors,
isError: isErrorInstructors,
} = useSubjectInstructorsQuery(computed(() => project.value?.subject_id));
const isDataLoading = computed(
() =>
isProjectLoading.value ||
isGroupLoading.value ||
isUserLoading.value ||
isUsersLoading.value
isUsersLoading.value ||
isLoadingInstructors.value
);
const isDataError = computed(
() => isProjectError.value || isGroupError.value || isUserError.value || isUsersError.value
() =>
isProjectError.value ||
isGroupError.value ||
isUserError.value ||
isUsersError.value ||
isErrorInstructors.value
);
const isTeacher = computed(() => user.value?.is_teacher || false);
const isTeacher = computed(() => {
if (!user.value || !instructors.value) {
return false;
}
return instructors.value.some((instructor) => instructor.uid === user.value.uid);
});
const { mutateAsync: createGroupMutate } = useCreateGroupsMutation();
Expand Down

0 comments on commit 6d56e63

Please sign in to comment.