fix:#79 added check for token and response feedback with toast

This commit is contained in:
masterElmar
2023-11-20 21:11:42 +01:00
parent ecb43abd6a
commit cf07db861f
4 changed files with 24 additions and 10 deletions

View File

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

View File

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

View File

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

View File

@@ -46,14 +46,23 @@ function loadCalendar(): void {
moduleStore().removeAllModules(); moduleStore().removeAllModules();
tokenStore().setToken(token.value); tokenStore().setToken(token.value);
getCalender(token.value).then((data) => { getCalender(token.value).then((data: Module[]) => {
if (data.length > 0) {
data.forEach((module) => { data.forEach((module) => {
moduleStore().addModule(module); moduleStore().addModule(module);
}); });
modules.value = data; 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> </script>