✨ Add timetable group feature
This commit is contained in:
44
src/store.js
44
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() {
|
||||
|
||||
Reference in New Issue
Block a user