advent22/ui/src/components/Calendar.vue

111 lines
2.8 KiB
Vue
Raw Normal View History

<!-- eslint-disable vue/multi-word-component-names -->
2023-09-07 00:41:38 +00:00
<template>
<MultiModal @handle="on_modal_handle" />
2023-09-07 00:41:38 +00:00
<BulmaToast @handle="on_toast_handle" class="content">
2023-11-11 01:22:30 +00:00
<p>
Du hast noch keine Türchen geöffnet, vielleicht gibt es ein Anzeigeproblem
in Deinem Webbrowser?
</p>
<div class="level">
<div class="level-item">
<BulmaButton
class="is-success"
text="Türchen anzeigen"
@click.left="
store.is_touch_device = true;
toast?.hide();
"
/>
</div>
<div class="level-item">
<BulmaButton
class="is-danger"
text="Ich möchte selbst suchen"
@click.left="toast?.hide()"
/>
</div>
</div>
</BulmaToast>
2023-09-09 23:52:58 +00:00
<figure>
<div class="image is-unselectable">
<img :src="ensure_loaded(store.background_image).data_url" />
2023-09-09 23:52:58 +00:00
<ThouCanvas>
<CalendarDoor
v-for="(door, index) in doors"
:key="`door-${index}`"
:door="door"
:visible="store.is_touch_device"
:title="name_door(door.day)"
@click="door_click(door.day)"
2023-11-21 22:33:11 +00:00
style="cursor: pointer"
2023-09-09 23:52:58 +00:00
/>
</ThouCanvas>
</div>
</figure>
2023-09-07 00:41:38 +00:00
</template>
<script setup lang="ts">
import { API } from "@/lib/api";
import { APIError } from "@/lib/api_error";
import { ensure_loaded, name_door } from "@/lib/helpers";
import { ImageData } from "@/lib/model";
2024-08-23 16:38:04 +00:00
import { Door } from "@/lib/rects/door";
import { advent22Store } from "@/lib/store";
2023-09-07 00:41:38 +00:00
import { onBeforeUnmount } from "vue";
import MultiModal, { HMultiModal } from "./MultiModal.vue";
2023-10-27 14:40:25 +00:00
import BulmaButton from "./bulma/Button.vue";
import BulmaToast, { HBulmaToast } from "./bulma/Toast.vue";
2023-09-07 02:08:56 +00:00
import CalendarDoor from "./calendar/CalendarDoor.vue";
import ThouCanvas from "./calendar/ThouCanvas.vue";
2023-09-07 00:41:38 +00:00
defineProps<{
doors: Door[];
}>();
2023-09-07 00:41:38 +00:00
const store = advent22Store();
2023-11-11 01:22:30 +00:00
let modal: HMultiModal | undefined;
let toast: HBulmaToast | undefined;
let toast_timeout: number | undefined;
2023-11-11 01:22:30 +00:00
function on_modal_handle(handle: HMultiModal) {
modal = handle;
}
2023-11-11 01:22:30 +00:00
function on_toast_handle(handle: HBulmaToast) {
toast = handle;
2023-11-11 01:22:30 +00:00
if (store.is_touch_device) return;
2023-11-11 01:22:30 +00:00
store.when_initialized(() => {
toast_timeout = setTimeout(() => {
if (store.user_doors.length === 0) return;
if (store.is_touch_device) return;
2023-09-07 00:41:38 +00:00
toast!.show({ duration: 600000, type: "is-warning" });
}, 10e3);
});
}
2023-11-11 01:47:54 +00:00
async function door_click(day: number) {
if (toast_timeout !== undefined) clearTimeout(toast_timeout);
toast?.hide();
if (modal === undefined) return;
modal.show_loading();
try {
const day_image = await API.request<ImageData>(`user/image_${day}`);
modal.show_image(day_image.data_url, name_door(day));
} catch (error) {
APIError.alert(error);
modal.hide();
}
2023-09-07 00:41:38 +00:00
}
onBeforeUnmount(() => toast?.hide());
2023-09-07 00:41:38 +00:00
</script>