Skip to content

Commit

Permalink
feat: add loading state to sign in button
Browse files Browse the repository at this point in the history
  • Loading branch information
Skolaczk committed Jun 7, 2024
1 parent 76dbda1 commit c28a70a
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/components/navbar/sign-in-button.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,25 @@
'use client';

import { useTransition } from 'react';
import { signIn } from 'next-auth/react';

import { Icons } from '@/components/icons';
import { Button } from '@/components/ui/button';
import * as m from '@/paraglide/messages';

export const SignInButton = () => {
return <Button onClick={() => signIn('github')}>{m.sign_in()}</Button>;
const [isPending, startTransition] = useTransition();

const handleSignIn = () => {
startTransition(async () => {
await signIn('github');
});
};

return (
<Button onClick={handleSignIn} disabled={isPending}>
{isPending && <Icons.loader className="mr-2 size-4 animate-spin" />}
{m.sign_in()}
</Button>
);
};

0 comments on commit c28a70a

Please sign in to comment.