@@ -2,6 +2,7 @@ import React from 'react';
2
2
import { Router , Link , navigate } from '@reach/router' ;
3
3
import './App.css' ;
4
4
import { useNetlifyIdentity } from './useNetlifyIdentity' ;
5
+ import useLoading from './useLoading' ;
5
6
6
7
let IdentityContext = React . createContext ( ) ;
7
8
@@ -22,10 +23,11 @@ function Login() {
22
23
const { loginUser, signupUser } = React . useContext ( IdentityContext ) ;
23
24
const formRef = React . useRef ( ) ;
24
25
const [ msg , setMsg ] = React . useState ( '' ) ;
26
+ const [ isLoading , load ] = useLoading ( ) ;
25
27
const signup = ( ) => {
26
28
const email = formRef . current . email . value ;
27
29
const password = formRef . current . password . value ;
28
- signupUser ( email , password )
30
+ load ( signupUser ( email , password ) )
29
31
. then ( user => {
30
32
console . log ( 'Success! Signed up' , user ) ;
31
33
navigate ( '/dashboard' ) ;
@@ -39,7 +41,7 @@ function Login() {
39
41
e . preventDefault ( ) ;
40
42
const email = e . target . email . value ;
41
43
const password = e . target . password . value ;
42
- loginUser ( email , password )
44
+ load ( loginUser ( email , password ) )
43
45
. then ( user => {
44
46
console . log ( 'Success! Logged in' , user ) ;
45
47
navigate ( '/dashboard' ) ;
@@ -59,11 +61,15 @@ function Login() {
59
61
< input type = "password" name = "password" />
60
62
</ label >
61
63
</ div >
62
- < div >
63
- < input type = "submit" value = "Log in" />
64
- < button onClick = { signup } > Sign Up </ button >
65
- { msg && < pre > { msg } </ pre > }
66
- </ div >
64
+ { isLoading ? (
65
+ < Spinner />
66
+ ) : (
67
+ < div >
68
+ < input type = "submit" value = "Log in" />
69
+ < button onClick = { signup } > Sign Up </ button >
70
+ { msg && < pre > { msg } </ pre > }
71
+ </ div >
72
+ ) }
67
73
</ form >
68
74
) ;
69
75
}
@@ -75,7 +81,7 @@ function Home() {
75
81
< p >
76
82
this is a < b > Public Page</ b > , not behind an authentication wall
77
83
</ p >
78
- < p style = { { backgroundColor : '#EEE' , padding : '1rem' } } >
84
+ < div style = { { backgroundColor : '#EEE' , padding : '1rem' } } >
79
85
< div >
80
86
< a
81
87
href = { `https://app.netlify.com/start/deploy?repository=https://github.com/netlify/create-react-app-lambda/tree/reachRouterAndGoTrueDemo&stack=cms` }
@@ -90,7 +96,7 @@ function Home() {
90
96
< a href = "https://github.com/netlify/create-react-app-lambda/tree/reachRouterAndGoTrueDemo" >
91
97
Open Source.
92
98
</ a > { ' ' }
93
- </ p >
99
+ </ div >
94
100
</ div >
95
101
) ;
96
102
}
@@ -99,18 +105,6 @@ function About() {
99
105
return < div > About</ div > ;
100
106
}
101
107
102
- function useLoading ( ) {
103
- const [ isLoading , setState ] = React . useState ( false ) ;
104
- const load = aPromise => {
105
- setState ( true ) ;
106
- return aPromise . then ( ( ...args ) => {
107
- setState ( false ) ;
108
- return Promise . resolve ( ...args ) ;
109
- } ) ;
110
- } ;
111
- return [ isLoading , load ] ;
112
- }
113
-
114
108
function Dashboard ( ) {
115
109
const props = React . useContext ( IdentityContext ) ;
116
110
const { isConfirmedUser, authedFetch } = props ;
0 commit comments