🏗️ Merge substitution filter and timetable filter
This commit is contained in:
28
src/store.js
28
src/store.js
@ -5,25 +5,13 @@ import router from "./router";
|
||||
export const lastRoute = ref();
|
||||
export const loading = ref(false);
|
||||
|
||||
export const substitutionFilter = ref(
|
||||
localStorage.getItem("substitutionFilter") || "all"
|
||||
);
|
||||
export const timetableClass = ref(
|
||||
localStorage.getItem("timetableClass") || "none"
|
||||
);
|
||||
export const classFilter = ref(localStorage.getItem("classFilter") || "none");
|
||||
export const timetableGroups = ref(
|
||||
JSON.parse(localStorage.getItem("timetableGroups") || "[]")
|
||||
);
|
||||
|
||||
watch(substitutionFilter, (newValue) => {
|
||||
if (newValue == "other") {
|
||||
newValue = prompt("Please enter a class to filter (e.g. 9C)");
|
||||
}
|
||||
localStorage.setItem("substitutionFilter", newValue);
|
||||
fetchData();
|
||||
});
|
||||
watch(timetableClass, (newValue) => {
|
||||
localStorage.setItem("timetableClass", newValue);
|
||||
watch(classFilter, (newValue) => {
|
||||
localStorage.setItem("classFilter", newValue);
|
||||
fetchData();
|
||||
});
|
||||
watch(timetableGroups, (newValue) => {
|
||||
@ -126,7 +114,7 @@ export async function fetchClassList() {
|
||||
|
||||
export async function fetchTimetable() {
|
||||
const timetableResponse = await fetch(
|
||||
`${baseUrl}/timetable?class=${timetableClass.value}`
|
||||
`${baseUrl}/timetable?class=${classFilter.value}`
|
||||
);
|
||||
const timetableData = await timetableResponse.json();
|
||||
if (timetableData.error) {
|
||||
@ -138,9 +126,9 @@ export async function fetchTimetable() {
|
||||
export async function fetchSubstitutions() {
|
||||
const requestDate = `?date=${selectedDate.value.getTime()}`;
|
||||
const substitutionResponse = await fetch(
|
||||
substitutionFilter.value == "all"
|
||||
classFilter.value == "none"
|
||||
? `${baseUrl}/substitutions${requestDate}`
|
||||
: `${baseUrl}/substitutions${requestDate}&class=${substitutionFilter.value}`
|
||||
: `${baseUrl}/substitutions${requestDate}&class=${classFilter.value}`
|
||||
);
|
||||
const substitutionData = await substitutionResponse.json();
|
||||
substitutions.value = substitutionData;
|
||||
@ -149,9 +137,9 @@ export async function fetchSubstitutions() {
|
||||
export async function fetchHistory() {
|
||||
const requestDate = `?date=${selectedDate.value.getTime()}`;
|
||||
const historyResponse = await fetch(
|
||||
substitutionFilter.value == "all"
|
||||
classFilter.value == "all"
|
||||
? `${baseUrl}/history${requestDate}`
|
||||
: `${baseUrl}/history${requestDate}&class=${substitutionFilter.value}`
|
||||
: `${baseUrl}/history${requestDate}&class=${classFilter.value}`
|
||||
);
|
||||
const historyData = await historyResponse.json();
|
||||
if (historyData.error) console.warn("API Error: " + historyData.error);
|
||||
|
||||
Reference in New Issue
Block a user