Skip to content

Commit

Permalink
feat: loading
Browse files Browse the repository at this point in the history
  • Loading branch information
purinx committed Dec 12, 2023
1 parent 823c01a commit 2568b11
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/app/auth/sign-in/SignInForm/index.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
'use client';

import { Field, Form, Label } from '@radix-ui/react-form';
import { useFormState } from 'react-dom';
import { useFormState, useFormStatus } from 'react-dom';

import { signIn } from '../actions';
import { ErrorMessage } from '@/lib/components/typographies';

/**
* @radix-ui/react-form が useContextを使っているのが憎い
*/
export const SignInForm = () => {
const { pending } = useFormStatus();
const [{ errors }, dispatch] = useFormState(signIn, { errors: {} });
return (
<Form role="form">
Expand Down Expand Up @@ -39,7 +37,12 @@ export const SignInForm = () => {
type="password"
/>
</Field>
<button formAction={dispatch} type="submit">
<button
formAction={dispatch}
type="submit"
aria-busy={pending}
aria-disabled={pending}
>
signIn
</button>
</Form>
Expand Down
1 change: 1 addition & 0 deletions src/app/auth/sign-in/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const SignInPage = () => {
<main className="container">
<h1>Sign In</h1>
<SignInForm />
<a href="/auth/register">{`>`} register</a>
</main>
);
};
Expand Down
7 changes: 7 additions & 0 deletions src/app/loading.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default function Loading() {
return (
<main className="center" aria-busy="true">
<h1>Loading</h1>
</main>
);
}

0 comments on commit 2568b11

Please sign in to comment.