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"
|
2023-11-02 00:37:00 +00:00
|
|
|
:icon="'fa-solid fa-toggle-' + (store.is_admin ? 'on' : '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";
|
2023-09-10 00:24:56 +00:00
|
|
|
|
|
|
|
|
import BulmaButton from "./bulma/Button.vue";
|
|
|
|
|
import LoginModal from "./LoginModal.vue";
|
|
|
|
|
|
2025-12-05 02:12:33 +00:00
|
|
|
let modal_visible = false;
|
|
|
|
|
let is_busy = false;
|
|
|
|
|
const store = advent22Store();
|
|
|
|
|
|
|
|
|
|
function on_click() {
|
|
|
|
|
if (store.is_admin) {
|
|
|
|
|
store.logout();
|
|
|
|
|
} else {
|
|
|
|
|
// show login modal
|
|
|
|
|
is_busy = true;
|
|
|
|
|
modal_visible = 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-05 02:12:33 +00:00
|
|
|
function on_submit(creds: Credentials) {
|
|
|
|
|
modal_visible = 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))
|
|
|
|
|
.finally(() => (is_busy = false));
|
|
|
|
|
}
|
2023-09-13 15:20:52 +00:00
|
|
|
|
2025-12-05 02:12:33 +00:00
|
|
|
function on_cancel() {
|
|
|
|
|
modal_visible = false;
|
|
|
|
|
is_busy = false;
|
2023-09-10 00:24:56 +00:00
|
|
|
}
|
|
|
|
|
</script>
|