advent22/ui/src/components/LoginModal.vue

87 lines
2.1 KiB
Vue
Raw Normal View History

2022-12-14 02:39:32 +00:00
<template>
2023-09-07 02:33:45 +00:00
<div v-show="active" class="modal is-active">
2022-12-14 02:39:32 +00:00
<div class="modal-background" />
<div class="modal-card">
<form @submit.prevent="submit">
<header class="modal-card-head">
<p class="modal-card-title">Login</p>
2023-09-07 02:33:45 +00:00
<button
class="delete"
aria-label="close"
@click.left="set_active(false)"
/>
2022-12-14 02:39:32 +00:00
</header>
<section class="modal-card-body">
<div class="field">
<label class="label">Username</label>
<div class="control">
2023-09-07 02:33:45 +00:00
<input
ref="username_input"
class="input"
type="text"
v-model="username"
/>
2022-12-14 02:39:32 +00:00
</div>
</div>
<div class="field">
<label class="label">Password</label>
<div class="control">
<input class="input" type="password" v-model="password" />
</div>
</div>
</section>
<footer class="modal-card-foot">
2023-09-07 02:33:45 +00:00
<button class="button is-success" @click.left="submit">Login</button>
2023-09-07 02:12:17 +00:00
<button class="button is-danger" @click.left="set_active(false)">
2022-12-14 02:39:32 +00:00
Cancel
</button>
</footer>
</form>
</div>
</div>
</template>
<script lang="ts">
import { Vue } from "vue-class-component";
2023-01-24 23:18:09 +00:00
export default class extends Vue {
2023-09-06 16:25:35 +00:00
public active = false;
public username = "";
public password = "";
2022-12-14 02:39:32 +00:00
2023-09-07 02:33:45 +00:00
declare $refs: {
username_input: HTMLInputElement | null | undefined;
};
2023-01-17 14:28:11 +00:00
public created() {
2022-12-21 23:51:25 +00:00
window.addEventListener("keydown", (e) => {
if (e.key == "Escape") this.set_active(false);
});
}
2023-01-17 14:28:11 +00:00
public set_active(state: boolean) {
2022-12-14 02:39:32 +00:00
this.active = state;
this.username = "";
this.password = "";
2023-09-07 02:33:45 +00:00
if (this.active) {
this.$nextTick(() => {
if (this.$refs.username_input instanceof HTMLInputElement) {
this.$refs.username_input?.focus();
}
});
}
2022-12-14 02:39:32 +00:00
}
2023-09-06 16:25:35 +00:00
public submit() {
2022-12-14 02:39:32 +00:00
this.$advent22.set_api_auth(this.username, this.password);
this.set_active(false);
}
}
</script>