|
1 | 1 | <script lang="ts"> |
2 | | - import { Card, Button, Label, Input } from 'flowbite-svelte'; |
| 2 | + import { tick } from 'svelte'; |
| 3 | + import { writable } from 'svelte/store'; |
| 4 | + import { Card, Button, Label, Input, Hr } from 'flowbite-svelte'; |
3 | 5 |
|
4 | 6 | // 必要なコンポーネントだけを読み込んで、コンパイルを時間を短縮 |
5 | | - import Checkbox from 'flowbite-svelte/Checkbox.svelte'; |
6 | 7 | import UserOutlineSolid from 'flowbite-svelte-icons/UserCircleSolid.svelte'; |
7 | 8 | import EyeOutline from 'flowbite-svelte-icons/EyeOutline.svelte'; |
8 | 9 | import EyeSlashOutline from 'flowbite-svelte-icons/EyeSlashOutline.svelte'; |
|
11 | 12 |
|
12 | 13 | import { |
13 | 14 | GUEST_USER_NAME, |
14 | | - GUEST_USER_PASSWORD, |
15 | | - // GUEST_USER_PASSWORD_FOR_LOCAL, |
| 15 | + // GUEST_USER_PASSWORD, |
| 16 | + GUEST_USER_PASSWORD_FOR_LOCAL, |
16 | 17 | LOGIN_LABEL, |
17 | 18 | } from '$lib/constants/forms'; |
18 | 19 |
|
|
25 | 26 | export let alternativePageLink: string; |
26 | 27 |
|
27 | 28 | const { form, message, errors, submitting, enhance } = formProperties; |
| 29 | + let isSubmitting = writable(false); |
28 | 30 |
|
29 | | - let isGuest: boolean = false; |
| 31 | + async function handleLoginAsGuest(event: Event) { |
| 32 | + if (!event || (event instanceof KeyboardEvent && event.key !== 'Enter')) { |
| 33 | + event.preventDefault(); |
| 34 | + return; |
| 35 | + } |
| 36 | +
|
| 37 | + event.preventDefault(); |
| 38 | + $isSubmitting = true; |
30 | 39 |
|
31 | | - $: if (isGuest) { |
32 | 40 | $form.username = GUEST_USER_NAME; |
33 | 41 |
|
34 | 42 | // HACK: ローカル環境のパスワードは一時的に書き換えて対応している |
35 | 43 | // |
36 | 44 | // See: |
37 | 45 | // src/lib/constants/forms.ts |
38 | | - // $form.password = GUEST_USER_PASSWORD_FOR_LOCAL; |
39 | | - $form.password = GUEST_USER_PASSWORD; |
40 | | - } else { |
41 | | - $form.username = ''; |
42 | | - $form.password = ''; |
| 46 | + $form.password = GUEST_USER_PASSWORD_FOR_LOCAL; |
| 47 | + // $form.password = GUEST_USER_PASSWORD; |
| 48 | +
|
| 49 | + // $formの更新後にフォームを送信 |
| 50 | + await tick(); |
| 51 | + const authForm = document.getElementById('auth-form') as HTMLFormElement; |
| 52 | +
|
| 53 | + if (authForm instanceof HTMLFormElement) { |
| 54 | + authForm.submit(); |
| 55 | + } else { |
| 56 | + console.error('Failed to submit the form'); |
| 57 | + } |
| 58 | +
|
| 59 | + $isSubmitting = false; |
43 | 60 | } |
44 | 61 |
|
45 | 62 | const UNFOCUSABLE = -1; |
|
53 | 70 | <!-- https://github.com/themesberg/flowbite-svelte-icons/tree/main/src/lib --> |
54 | 71 | <div class="container mx-auto py-8 w-5/6 flex flex-col items-center"> |
55 | 72 | <Card class="w-full max-w-md"> |
56 | | - <form method="post" use:enhance class="flex flex-col space-y-6"> |
| 73 | + <form id="auth-form" method="post" use:enhance class="flex flex-col space-y-6"> |
57 | 74 | <h3 class="text-xl font-medium text-gray-900 dark:text-white">{title}</h3> |
58 | 75 |
|
59 | 76 | <MessageHelperWrapper message={$message} /> |
60 | 77 |
|
61 | 78 | {#if title === LOGIN_LABEL} |
62 | | - <Checkbox bind:checked={isGuest}>お試し用のアカウントを使う</Checkbox> |
| 79 | + <Button |
| 80 | + type="button" |
| 81 | + class="w-full" |
| 82 | + on:click={handleLoginAsGuest} |
| 83 | + on:keydown={handleLoginAsGuest} |
| 84 | + disabled={$submitting || $isSubmitting} |
| 85 | + > |
| 86 | + <div class="text-md">お試し用のアカウントでログイン</div> |
| 87 | + </Button> |
63 | 88 | {/if} |
64 | 89 |
|
| 90 | + <div> |
| 91 | + <Hr classHr="my-2 h-0.5 bg-gray-400 dark:bg-gray-200" /> |
| 92 | + </div> |
| 93 | + |
65 | 94 | <!-- User name --> |
66 | 95 | <div class="space-y-2"> |
67 | 96 | <Label for="username-in-auth-form"> |
|
0 commit comments