Skip to content
Snippets Groups Projects
Commit 17d55feb authored by Julian's avatar Julian
Browse files

Fix duplicate key errors

parent ca89d63b
No related branches found
No related tags found
1 merge request!50Resolve "Implement bundled courses/lessons"
......@@ -122,7 +122,7 @@ export default defineComponent({
<v-card-subtitle
class="color pa-0 ma-0 d-flex flex-wrap justify-center small-gap"
>
<span v-for="teacher in teachers" :key="teacher.id">
<span v-for="teacher in teachers" :key="'teacher-' + teacher.id">
<v-tooltip bottom>
<template #activator="{ on, attrs }">
<colored-short-name-chip
......@@ -139,7 +139,7 @@ export default defineComponent({
</v-tooltip>
</span>
<!-- Show rooms -->
<span v-for="room in rooms" :key="room.id">
<span v-for="room in rooms" :key="'room-' + room.id">
<v-tooltip bottom>
<template #activator="{ on, attrs }">
<colored-short-name-chip
......
......@@ -3,6 +3,21 @@
*/
export default {
methods: {
/**
* Removes duplicate objects from an array based on their `id` property.
*
* @param {Array<{id: string|number, [key: string]: any}>} array - An array of objects, each having an `id` property and possibly other attributes.
* @return {Array<{id: string|number, [key: string]: any}>} - A new array with duplicates removed.
*/
removeDuplicatesById(array) {
return array.filter(
(value, index, self) =>
index ===
self.findIndex(
(t) => t.place === value.place && t.name === value.name,
),
);
},
bundleChildren(bundle) {
return bundle.courses || bundle.lessons;
},
......@@ -10,19 +25,19 @@ export default {
const subjects = this.bundleChildren(bundle).flatMap(
(child) => child.subject,
);
return [...new Set(subjects)];
return this.removeDuplicatesById(subjects);
},
bundleTeachers(bundle) {
const teachers = this.bundleChildren(bundle).flatMap(
(child) => child.teachers,
);
return [...new Set(teachers)];
return this.removeDuplicatesById(teachers);
},
bundleRooms(bundle) {
const rooms = bundle.courses
? bundle.courses.map((course) => course.defaultRoom)
: bundle.lessons.flatMap((lesson) => lesson.rooms);
return [...new Set(rooms.filter((room) => room))];
return this.removeDuplicatesById(rooms.filter((room) => room));
},
},
};
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment