Skip to content

Commit

Permalink
Hotfix (#337)
Browse files Browse the repository at this point in the history
* chore: use pinia

* chore: projectcard group props

* fix: linting errors
  • Loading branch information
francisvaut authored Apr 18, 2024
1 parent 218cfc5 commit 441830a
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
12 changes: 12 additions & 0 deletions frontend/src/components/projects/ProjectCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import MeterGroup from 'primevue/metergroup';
import Card from 'primevue/card';
import Button from 'primevue/button';
import { type Project } from '@/types/Project.ts';
import { type Group } from '@/types/Group.ts';
import { PrimeIcons } from 'primevue/api';
import { useI18n } from 'vue-i18n';
import { computed, watch } from 'vue';
Expand All @@ -21,6 +22,8 @@ const props = withDefaults(
type?: 'small' | 'large';
project: Project;
course: Course;
projectGroups: Group[];
studentGroups: Group[];
}>(),
{
type: 'large',
Expand Down Expand Up @@ -60,6 +63,13 @@ const meterItems = computed(() => {
const { t } = useI18n();
const { submissionStatus, getSubmissionStatusByProject } = useSubmissionStatus();
/**
* Return True if the user is in a group in this project.
*/
function isInGroup(): boolean {
return props.studentGroups.some((group) => props.projectGroups.includes(group));
}
/* Watchers */
watch(
props.course,
Expand Down Expand Up @@ -177,11 +187,13 @@ watch(
/>
</RouterLink>
<RouterLink
v-if="isInGroup()"
:to="{
name: 'submission',
params: {
courseId: course.id,
projectId: project.id,
groupId: '5',
},
}"
>
Expand Down
36 changes: 35 additions & 1 deletion frontend/src/components/projects/ProjectList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@ import moment from 'moment';
import Skeleton from 'primevue/skeleton';
import InputSwitch from 'primevue/inputswitch';
import ProjectCard from '@/components/projects/ProjectCard.vue';
import { computed, ref } from 'vue';
import { computed, ref, watch } from 'vue';
import { useI18n } from 'vue-i18n';
import { type Project } from '@/types/Project.ts';
import { type Group } from '@/types/Group.ts';
import { storeToRefs } from 'pinia';
import { useAuthStore } from '@/store/authentication.store.ts';
import { useStudents } from '@/composables/services/student.service';
/* Props */
const props = withDefaults(
Expand All @@ -21,10 +25,36 @@ const props = withDefaults(
/* Composables */
const { t } = useI18n();
const { user } = storeToRefs(useAuthStore());
const { student, getStudentByID } = useStudents();
/**
* Get the groups of the corresponding users
*/
function getUserGroups(): Group[] {
if (user.value !== null && user.value?.isStudent()) {
// eslint-disable-next-line @typescript-eslint/prefer-optional-chain
return student.value !== null && student.value.groups !== null ? student.value?.groups : [];
}
return [];
}
/* State */
const showPast = ref(false);
/* Watchers */
watch(
user,
() => {
if (user.value !== null && user.value.isStudent()) {
getStudentByID(user.value.id);
}
},
{
immediate: true,
},
);
/* Sorts the projects by deadline */
const sortedProjects = computed<Project[] | null>(() => {
const projects =
Expand Down Expand Up @@ -68,6 +98,8 @@ const incomingProjects = computed<Project[] | null>(() => {
type="small"
:project="project"
:course="project.course"
:projectGroups="project.groups"
:studentGroups="getUserGroups()"
v-if="project.course !== null"
/>
</div>
Expand Down Expand Up @@ -97,6 +129,8 @@ const incomingProjects = computed<Project[] | null>(() => {
class="h-100"
:project="project"
:course="project.course"
:projectGroups="project.groups"
:studentGroups="getUserGroups()"
v-if="project.course !== null"
/>
</div>
Expand Down

0 comments on commit 441830a

Please sign in to comment.