🚸 ♻️ Refactor store and improve UX

- Move view related functions out of the store
- Restructure the store.js file
- Improve error handling of `/check`
- Show red loading spinner if data fetch failed
- Prefetch current, next and previous day instead of only current
- Refactor some other frontend file
This commit is contained in:
2023-01-01 23:09:53 +01:00
parent 951a8c51f0
commit d22755d8c3
6 changed files with 165 additions and 142 deletions

View File

@@ -1,5 +1,5 @@
<script setup>
import { historyOfDate } from "../store";
import { history } from "../store";
import { getSubstitutionText } from "../util";
import { computed } from "vue";
import dayjs from "dayjs";
@@ -10,39 +10,27 @@ const props = defineProps({
},
});
const history = computed(() => {
return historyOfDate.value[props.date.setUTCHours(0, 0, 0, 0)];
const historyOfDate = computed(() => {
return history.value[props.date.getTime()];
});
function getChar(type) {
switch (type) {
case "change":
return "~";
case "addition":
return "+";
case "deletion":
return "-";
}
}
function getColor(type) {
switch (type) {
case "change":
return "background-color: var(--substitution-background-change)";
case "addition":
return "background-color: var(--substitution-background-addition);";
case "deletion":
return "background-color: var(--substitution-background-deletion);";
}
}
const chars = {
change: "~",
addition: "+",
deletion: "-",
};
</script>
<template>
<div class="history">
<template v-for="event in history" :key="event">
<div class="change" :style="getColor(event.type)">
<span class="hour">{{ event.lesson }}{{ getChar(event.type) }}</span>
<template v-for="event in historyOfDate" :key="event">
<div
class="change"
:style="`background-color: var(--substitution-background-${event.type}`"
>
<span class="hour">{{ event.lesson }}{{ chars[event.type] }}</span>
<div class="infos">
<!-- If the entry is a change show which values changed -->
<span class="text" v-if="event.type == 'change'">
<template v-for="(change, key) in event.change" :key="key">
<p>
@@ -52,6 +40,7 @@ function getColor(type) {
</p>
</template>
</span>
<!-- If the entry is an addition or deletion generate a text -->
<span class="text" v-else
>{{
$t(getSubstitutionText(event.change), {