Merge pull request #80 from HTWK-Leipzig/79-edit-calender-loading-block

fix:#79 added check for token and response feedback with toast
This commit is contained in:
masterElmar
2023-11-20 22:36:15 +01:00
committed by GitHub
4 changed files with 28 additions and 14 deletions

View File

@@ -6,9 +6,13 @@ export async function getCalender(token: string): Promise<Module[]> {
method: "GET",
});
return await fetch(request)
.then((response) => {
return response.json();
})
.then((calendarResponse: Calendar) => calendarResponse.modules);
return await fetch(request).then((response) => {
if (response.ok) {
return response
.json()
.then((calendarResponse: Calendar) => calendarResponse.modules);
} else {
return [];
}
});
}

View File

@@ -49,7 +49,8 @@
"invalidToken": "Ungültiger Token",
"headline": "Bearbeite deinen HTWKalender",
"subTitle": "Füge deinen Link oder Token ein um den Kalender zu bearbeiten",
"loadCalendar": "Kalender laden"
"loadCalendar": "Kalender laden",
"noCalendarFound": "Keinen Kalender gefunden"
},
"additionalModules": {
"subTitle": "Füge weitere Module hinzu die nicht in deinem Studiengang enthalten sind.",

View File

@@ -49,7 +49,8 @@
"invalidToken": "invalid token",
"headline": "edit your HTWKalender",
"subTitle": "please enter your link or calendar token",
"loadCalendar": "load calendar"
"loadCalendar": "load calendar",
"noCalendarFound": "no calendar found"
},
"additionalModules": {
"subTitle": "Select additional Modules that are not listed in the regular semester for your Course",

View File

@@ -46,14 +46,22 @@ function loadCalendar(): void {
moduleStore().removeAllModules();
tokenStore().setToken(token.value);
getCalender(token.value).then((data) => {
data.forEach((module) => {
moduleStore().addModule(module);
});
modules.value = data;
getCalender(token.value).then((data: Module[]) => {
if (data.length > 0) {
data.forEach((module) => {
moduleStore().addModule(module);
});
modules.value = data;
router.push("/edit-additional-modules");
} else {
toast.add({
severity: "error",
summary: t("editCalendarView.error"),
detail: t("editCalendarView.noCalendarFound"),
life: 3000,
});
}
});
router.push("/edit-additional-modules");
}
</script>