diff --git a/src/store.js b/src/store.js index 21e71a7..97e5c79 100644 --- a/src/store.js +++ b/src/store.js @@ -11,6 +11,9 @@ export const substitutionFilter = ref( export const timetableClass = ref( localStorage.getItem("timetableClass") || "none" ); +export const timetableGroups = ref( + JSON.parse(localStorage.getItem("timetableGroups") || "[]") +); watch(substitutionFilter, (newValue) => { if (newValue == "other") { @@ -23,6 +26,10 @@ watch(timetableClass, (newValue) => { localStorage.setItem("timetableClass", newValue); fetchData(); }); +watch(timetableGroups, (newValue) => { + localStorage.setItem("timetableGroups", JSON.stringify(newValue)); + fetchData(); +}); export const selectedDate = ref(new Date(new Date().setUTCHours(0, 0, 0, 0))); export const selectedDay = computed(() => selectedDate.value.getDay() - 1); @@ -56,14 +63,45 @@ export const parsedTimetable = computed(() => { return timetable.value.map((day) => { const newDay = []; for (const lesson of day) { - const lessonLength = lesson.length || 1; - delete lesson.length; - for (var i = 0; i < lessonLength; i++) newDay.push(lesson); + var usedLesson = lesson; + // Check for timetable groups + if (Array.isArray(lesson)) { + var matchingLesson = lesson.find((e) => + timetableGroups.value.includes(e.group) + ); + if (!matchingLesson) { + matchingLesson = { + subject: "???", + teacher: "Please configure a timetable group in the settings", + length: lesson[0].length || 1, + }; + } + usedLesson = matchingLesson; + } + const lessonLength = usedLesson.length || 1; + delete usedLesson.length; + for (var i = 0; i < lessonLength; i++) newDay.push(usedLesson); } return newDay; }); }); +export const possibleTimetableGroups = computed(() => { + const foundTimetableGroups = []; + for (const day of timetable.value) { + for (const lesson of day) { + if (Array.isArray(lesson)) { + for (const group of lesson) { + if (!foundTimetableGroups.includes(group.group)) { + foundTimetableGroups.push(group.group); + } + } + } + } + } + return foundTimetableGroups; +}); + const baseUrl = import.meta.env.VITE_API_ENDPOINT || "/api"; export async function fetchData() { diff --git a/src/views/SettingsView.vue b/src/views/SettingsView.vue index 90f8c3f..c9a2587 100644 --- a/src/views/SettingsView.vue +++ b/src/views/SettingsView.vue @@ -1,6 +1,11 @@