feat: use static data instead of fetching from the API
This commit is contained in:
71
src/store.js
71
src/store.js
@ -1,6 +1,13 @@
|
||||
import { ref, watch, computed } from "vue";
|
||||
import { getNextAndPrevDay, setUTCMidnight } from "@/util";
|
||||
import i18n from "@/i18n";
|
||||
import {
|
||||
DEMO_CLASS_LIST,
|
||||
DEMO_SESSION_INFO,
|
||||
DEMO_TIMETABLE,
|
||||
getDemoHistory,
|
||||
getDemoSubstitutions,
|
||||
} from "./demoData";
|
||||
|
||||
/* Router */
|
||||
export const shouldLogin = ref(false);
|
||||
@ -15,7 +22,7 @@ export const profiles = ref(
|
||||
id: 0,
|
||||
name: "Default Profile",
|
||||
classFilter: "none",
|
||||
timetableId: "none",
|
||||
timetableId: 1,
|
||||
timetableGroups: [],
|
||||
},
|
||||
],
|
||||
@ -162,16 +169,7 @@ watch(selectedDate, () =>
|
||||
|
||||
export async function fetchSessionInfo() {
|
||||
try {
|
||||
const checkResponse = await fetch(`${baseUrl}/info`);
|
||||
if (checkResponse.status == 401) {
|
||||
shouldLogin.value = true;
|
||||
return false;
|
||||
} else if (checkResponse.status != 200) {
|
||||
console.log("Other error while fetching data: " + checkResponse.status);
|
||||
return false;
|
||||
} else {
|
||||
sessionInfo.value = await checkResponse.json();
|
||||
}
|
||||
sessionInfo.value = DEMO_SESSION_INFO;
|
||||
} catch {
|
||||
console.log("Error while fetching data: No internet connection!");
|
||||
return false;
|
||||
@ -180,53 +178,32 @@ export async function fetchSessionInfo() {
|
||||
}
|
||||
|
||||
export async function fetchClassList() {
|
||||
const classListResponse = await fetch(`${baseUrl}/classes`);
|
||||
const classListData = await classListResponse.json();
|
||||
classList.value = classListData;
|
||||
classList.value = DEMO_CLASS_LIST;
|
||||
}
|
||||
|
||||
export async function fetchTimetables() {
|
||||
const timetableResponse = await fetch(
|
||||
`${baseUrl}/timetable?class=${activeProfile.value.classFilter}`,
|
||||
);
|
||||
const timetableData = await timetableResponse.json();
|
||||
if (timetableData.error) {
|
||||
console.warn("API Error: " + timetableData.error);
|
||||
timetables.value = [];
|
||||
if (activeProfile.value.classFilter == "Demo") {
|
||||
timetables.value = DEMO_TIMETABLE.timetables;
|
||||
} else {
|
||||
timetables.value = timetableData.timetables;
|
||||
times.value = timetableData.times;
|
||||
|
||||
cachedTimetables.value[activeProfileId.value] =
|
||||
structuredClone(timetableData);
|
||||
for (const timetable of cachedTimetables.value[activeProfileId.value]
|
||||
.timetables) {
|
||||
timetable.fromCache = true;
|
||||
}
|
||||
timetables.value = [];
|
||||
}
|
||||
times.value = DEMO_TIMETABLE.times;
|
||||
}
|
||||
|
||||
export async function fetchSubstitutions(day) {
|
||||
const requestDate = `?date=${day}`;
|
||||
const substitutionResponse = await fetch(
|
||||
activeProfile.value.classFilter == "none"
|
||||
? `${baseUrl}/substitutions${requestDate}`
|
||||
: `${baseUrl}/substitutions${requestDate}&class=${activeProfile.value.classFilter}`,
|
||||
);
|
||||
const substitutionData = await substitutionResponse.json();
|
||||
substitutions.value[day] = substitutionData;
|
||||
if (activeProfile.value.classFilter == "Demo") {
|
||||
substitutions.value[day] = getDemoSubstitutions(day);
|
||||
} else {
|
||||
substitutions.value[day] = [];
|
||||
}
|
||||
}
|
||||
|
||||
export async function fetchHistory(day) {
|
||||
const requestDate = `?date=${day}`;
|
||||
const historyResponse = await fetch(
|
||||
activeProfile.value.classFilter == "none"
|
||||
? `${baseUrl}/history${requestDate}`
|
||||
: `${baseUrl}/history${requestDate}&class=${activeProfile.value.classFilter}`,
|
||||
);
|
||||
const historyData = await historyResponse.json();
|
||||
if (historyData.error) console.warn("API Error: " + historyData.error);
|
||||
else history.value[day] = historyData;
|
||||
if (activeProfile.value.classFilter == "Demo") {
|
||||
history.value[day] = getDemoHistory(day);
|
||||
} else {
|
||||
history.value[day] = [];
|
||||
}
|
||||
}
|
||||
|
||||
/* Preprocess the timetable data */
|
||||
|
Reference in New Issue
Block a user