✨ Implement caching of timetable data
This commit is contained in:
51
src/store.js
51
src/store.js
@ -30,19 +30,6 @@ export const activeProfileId = ref(
|
|||||||
localStorage.getItem("activeProfile") || profiles.value[0].id,
|
localStorage.getItem("activeProfile") || profiles.value[0].id,
|
||||||
);
|
);
|
||||||
|
|
||||||
watch(
|
|
||||||
() => activeProfile.value.classFilter,
|
|
||||||
() => {
|
|
||||||
fetchData(getNextAndPrevDay(selectedDate.value), false);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
export const localTimetables = ref(
|
|
||||||
JSON.parse(localStorage.getItem("timetables")) || [],
|
|
||||||
);
|
|
||||||
|
|
||||||
export const theme = ref(localStorage.getItem("theme") || "auto");
|
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
profiles,
|
profiles,
|
||||||
(newValue) => {
|
(newValue) => {
|
||||||
@ -53,6 +40,27 @@ watch(
|
|||||||
watch(activeProfileId, (newValue) => {
|
watch(activeProfileId, (newValue) => {
|
||||||
localStorage.setItem("activeProfile", newValue);
|
localStorage.setItem("activeProfile", newValue);
|
||||||
});
|
});
|
||||||
|
watch(
|
||||||
|
() => activeProfile.value.classFilter,
|
||||||
|
() => {
|
||||||
|
fetchData(getNextAndPrevDay(selectedDate.value), false);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
export const cachedTimetables = ref(
|
||||||
|
JSON.parse(localStorage.getItem("cachedTimetables")) || {},
|
||||||
|
);
|
||||||
|
export const localTimetables = ref(
|
||||||
|
JSON.parse(localStorage.getItem("timetables")) || [],
|
||||||
|
);
|
||||||
|
|
||||||
|
watch(
|
||||||
|
cachedTimetables,
|
||||||
|
(newValue) => {
|
||||||
|
localStorage.setItem("cachedTimetables", JSON.stringify(newValue));
|
||||||
|
},
|
||||||
|
{ deep: true },
|
||||||
|
);
|
||||||
watch(
|
watch(
|
||||||
localTimetables,
|
localTimetables,
|
||||||
(newValue) => {
|
(newValue) => {
|
||||||
@ -60,6 +68,8 @@ watch(
|
|||||||
},
|
},
|
||||||
{ deep: true },
|
{ deep: true },
|
||||||
);
|
);
|
||||||
|
|
||||||
|
export const theme = ref(localStorage.getItem("theme") || "auto");
|
||||||
watch(theme, (newValue) => {
|
watch(theme, (newValue) => {
|
||||||
localStorage.setItem("theme", newValue);
|
localStorage.setItem("theme", newValue);
|
||||||
});
|
});
|
||||||
@ -92,8 +102,12 @@ export const timetable = computed(() => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
export const sessionInfo = ref({});
|
export const sessionInfo = ref({});
|
||||||
export const timetables = ref([]);
|
export const timetables = ref(
|
||||||
export const times = ref([]);
|
(cachedTimetables.value[activeProfileId.value] || {}).timetables || [],
|
||||||
|
);
|
||||||
|
export const times = ref(
|
||||||
|
(cachedTimetables.value[activeProfileId.value] || {}).times || [],
|
||||||
|
);
|
||||||
export const substitutions = ref({});
|
export const substitutions = ref({});
|
||||||
export const history = ref({});
|
export const history = ref({});
|
||||||
export const classList = ref([]);
|
export const classList = ref([]);
|
||||||
@ -182,6 +196,13 @@ export async function fetchTimetables() {
|
|||||||
} else {
|
} else {
|
||||||
timetables.value = timetableData.timetables;
|
timetables.value = timetableData.timetables;
|
||||||
times.value = timetableData.times;
|
times.value = timetableData.times;
|
||||||
|
|
||||||
|
cachedTimetables.value[activeProfileId.value] =
|
||||||
|
structuredClone(timetableData);
|
||||||
|
for (const timetable of cachedTimetables.value[activeProfileId.value]
|
||||||
|
.timetables) {
|
||||||
|
timetable.fromCache = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user