11import "./App.css"
22
33import { framer } from "framer-plugin"
4- import { useLayoutEffect , useRef } from "react"
4+ import { useLayoutEffect , useRef , useState } from "react"
55import auth from "./auth"
66import { showLoginUI } from "./ui"
77
@@ -10,6 +10,7 @@ interface AuthenticationProps {
1010}
1111
1212export function Authenticate ( { onAuthenticated } : AuthenticationProps ) {
13+ const [ isLoading , setIsLoading ] = useState ( false )
1314 const pollInterval = useRef < number | ReturnType < typeof setInterval > > ( )
1415
1516 useLayoutEffect ( ( ) => {
@@ -35,6 +36,8 @@ export function Authenticate({ onAuthenticated }: AuthenticationProps) {
3536 const login = ( event : React . FormEvent < HTMLFormElement > ) => {
3637 event . preventDefault ( )
3738
39+ setIsLoading ( true )
40+
3841 const task = async ( ) => {
3942 try {
4043 // Retrieve the auth URL and a set of read and write keys
@@ -49,6 +52,8 @@ export function Authenticate({ onAuthenticated }: AuthenticationProps) {
4952 onAuthenticated ( )
5053 } catch ( e ) {
5154 framer . notify ( e instanceof Error ? e . message : "An unknown error ocurred" )
55+ } finally {
56+ setIsLoading ( false )
5257 }
5358 }
5459
@@ -67,8 +72,8 @@ export function Authenticate({ onAuthenticated }: AuthenticationProps) {
6772 < li > Map the table fields to the CMS</ li >
6873 </ ol >
6974
70- < button className = "action-button" type = "submit" >
71- Log In
75+ < button className = "action-button" type = "submit" aria-label = { isLoading ? "Logging in" : "Log in" } >
76+ { isLoading ? < div className = "framer-spinner" /> : " Log In" }
7277 </ button >
7378 </ form >
7479 )
0 commit comments