advent22/ui/src/components/calendar/CalendarDoor.vue

59 lines
1.4 KiB
Vue
Raw Normal View History

2022-10-30 01:27:46 +00:00
<template>
2023-09-07 02:12:17 +00:00
<SVGRect :rectangle="door.position" :focused="false" @click.left="on_click" />
2022-10-30 01:27:46 +00:00
</template>
<script lang="ts">
2023-09-07 02:08:56 +00:00
import { Door } from "@/lib/door";
2023-09-07 00:41:38 +00:00
import { AxiosError } from "axios";
2023-09-06 16:25:35 +00:00
import { Options, Vue } from "vue-class-component";
2023-09-07 00:41:38 +00:00
2023-09-07 02:08:56 +00:00
import SVGRect from "./SVGRect.vue";
2022-10-30 01:27:46 +00:00
@Options({
2023-09-07 00:41:38 +00:00
components: {
SVGRect,
},
2022-10-30 01:27:46 +00:00
props: {
2023-09-07 00:41:38 +00:00
door: Door,
2022-10-30 01:27:46 +00:00
},
2023-09-07 01:17:14 +00:00
emits: ["doorClick", "doorSuccess", "doorFailure"],
2022-10-30 01:27:46 +00:00
})
2023-01-24 23:18:09 +00:00
export default class extends Vue {
2023-09-07 00:41:38 +00:00
public door!: Door;
2022-10-30 03:10:07 +00:00
2023-09-06 16:25:35 +00:00
public on_click() {
2023-09-07 00:41:38 +00:00
this.$emit("doorClick");
2023-09-06 18:44:19 +00:00
2023-09-07 15:12:46 +00:00
this.$advent22
2023-09-12 13:55:08 +00:00
.api_get_blob(`images/${this.door.day}`)
2023-09-07 15:12:46 +00:00
.then((data) => this.$emit("doorSuccess", data))
.catch(([reason]) => {
2023-09-07 00:41:38 +00:00
let msg = "Unbekannter Fehler, bitte wiederholen!";
2023-09-10 21:37:29 +00:00
if (reason instanceof AxiosError) {
if (reason.code === "ECONNABORTED") {
// API unerreichbar
msg = "API antwortet nicht, bitte später wiederholen!";
} else if (reason.response !== undefined) {
if (reason.response.status === 401) {
// 401 UNAUTHORIZED
msg = "Netter Versuch :)";
} else if (reason.response.status === 422) {
// 422 UNPROCESSABLE ENTITY
msg = "Türchen ist kaputt, bitte Admin benachrichtigen!";
}
}
2023-09-07 00:41:38 +00:00
}
this.$emit("doorFailure", msg);
2023-09-07 15:12:46 +00:00
});
}
2022-10-30 01:27:46 +00:00
}
</script>
2023-09-07 00:41:38 +00:00
2023-09-09 21:41:06 +00:00
<style scoped>
2023-09-07 00:41:38 +00:00
rect {
cursor: pointer;
}
2023-09-07 01:17:14 +00:00
</style>