2023-09-10 00:24:56 +00:00
|
|
|
<template>
|
2023-09-13 15:20:52 +00:00
|
|
|
<LoginModal v-if="modal_visible" @submit="on_submit" @cancel="on_cancel" />
|
2023-09-10 00:24:56 +00:00
|
|
|
|
|
|
|
|
<BulmaButton
|
2023-09-22 20:42:28 +00:00
|
|
|
v-bind="$attrs"
|
2025-12-28 16:24:25 +00:00
|
|
|
:icon="['fas', store.is_admin ? 'fa-toggle-on' : 'fa-toggle-off']"
|
2023-09-12 22:35:57 +00:00
|
|
|
:busy="is_busy"
|
2023-09-20 22:03:32 +00:00
|
|
|
text="Admin"
|
|
|
|
|
@click.left="on_click"
|
2023-09-10 00:24:56 +00:00
|
|
|
/>
|
|
|
|
|
</template>
|
|
|
|
|
|
2025-12-05 02:12:33 +00:00
|
|
|
<script setup lang="ts">
|
2024-08-27 00:25:42 +00:00
|
|
|
import { APIError } from "@/lib/api_error";
|
2024-08-23 16:38:04 +00:00
|
|
|
import { Credentials } from "@/lib/model";
|
|
|
|
|
import { advent22Store } from "@/lib/store";
|
2025-12-07 03:28:00 +00:00
|
|
|
import { ref } from "vue";
|
2023-09-10 00:24:56 +00:00
|
|
|
|
|
|
|
|
import BulmaButton from "./bulma/Button.vue";
|
|
|
|
|
import LoginModal from "./LoginModal.vue";
|
|
|
|
|
|
2025-12-07 03:28:00 +00:00
|
|
|
const modal_visible = ref(false);
|
|
|
|
|
const is_busy = ref(false);
|
2025-12-05 02:12:33 +00:00
|
|
|
const store = advent22Store();
|
|
|
|
|
|
2025-12-28 16:35:10 +00:00
|
|
|
function on_click(): void {
|
2025-12-05 02:12:33 +00:00
|
|
|
if (store.is_admin) {
|
|
|
|
|
store.logout();
|
|
|
|
|
} else {
|
|
|
|
|
// show login modal
|
2025-12-07 03:28:00 +00:00
|
|
|
is_busy.value = true;
|
|
|
|
|
modal_visible.value = true;
|
2023-09-11 23:36:36 +00:00
|
|
|
}
|
2025-12-05 02:12:33 +00:00
|
|
|
}
|
2023-09-11 23:10:17 +00:00
|
|
|
|
2025-12-28 16:35:10 +00:00
|
|
|
async function on_submit(creds: Credentials): Promise<void> {
|
2025-12-07 03:28:00 +00:00
|
|
|
modal_visible.value = false;
|
2023-09-11 23:10:17 +00:00
|
|
|
|
2025-12-05 02:12:33 +00:00
|
|
|
store
|
|
|
|
|
.login(creds)
|
|
|
|
|
.catch((error) => APIError.alert(error))
|
2025-12-07 03:28:00 +00:00
|
|
|
.finally(() => (is_busy.value = false));
|
2025-12-05 02:12:33 +00:00
|
|
|
}
|
2023-09-13 15:20:52 +00:00
|
|
|
|
2025-12-28 16:35:10 +00:00
|
|
|
function on_cancel(): void {
|
2025-12-07 03:28:00 +00:00
|
|
|
modal_visible.value = false;
|
|
|
|
|
is_busy.value = false;
|
2023-09-10 00:24:56 +00:00
|
|
|
}
|
|
|
|
|
</script>
|