@@ -4,7 +4,7 @@ import { useCurrentUser } from '../lib/hooks';
44
55const ProfileSection = ( ) => {
66 const [ user , { mutate } ] = useCurrentUser ( ) ;
7- const [ isUpdating , setIsUpdating ] = useState ( false ) ;
7+ const [ loading , isLoading ] = useState ( false ) ;
88 const nameRef = useRef ( ) ;
99 const bioRef = useRef ( ) ;
1010 const profilePictureRef = useRef ( ) ;
@@ -17,19 +17,15 @@ const ProfileSection = () => {
1717
1818 const handleSubmit = async ( event ) => {
1919 event . preventDefault ( ) ;
20-
21- console . log ( nameRef . current . value ) ;
22-
20+ isLoading ( true ) ;
2321 const formData = new FormData ( ) ;
24-
2522 if ( profilePictureRef . current . files [ 0 ] ) { formData . append ( 'profilePicture' , profilePictureRef . current . files [ 0 ] ) ; }
2623 formData . append ( 'name' , nameRef . current . value ) ;
2724 formData . append ( 'bio' , bioRef . current . value ) ;
2825
29-
3026 const res = await fetch ( '/api/user' , {
3127 method : 'PATCH' ,
32- body :formData ,
28+ body : formData ,
3329 } ) ;
3430 if ( res . status === 200 ) {
3531 const userData = await res . json ( ) ;
@@ -43,9 +39,11 @@ const ProfileSection = () => {
4339 } else {
4440 setMsg ( { message : await res . text ( ) , isError : true } ) ;
4541 }
42+ isLoading ( false ) ;
4643 } ;
4744
4845 const handleSubmitPasswordChange = async ( e ) => {
46+ isLoading ( true ) ;
4947 e . preventDefault ( ) ;
5048 const body = {
5149 oldPassword : e . currentTarget . oldPassword . value ,
@@ -65,13 +63,17 @@ const ProfileSection = () => {
6563 } else {
6664 setMsg ( { message : await res . text ( ) , isError : true } ) ;
6765 }
66+ isLoading ( false ) ;
6867 } ;
6968
7069 return (
7170 < >
7271 < Head >
7372 < title > Settings</ title >
7473 </ Head >
74+ { loading ? < div className = "progress" style = { { margin : 0 } } >
75+ < div className = "indeterminate" > </ div >
76+ </ div > : null }
7577 < section className = "" >
7678 < h2 > Edit Profile</ h2 >
7779 { msg . message ? < p style = { { color : msg . isError ? 'red' : '#0070f3' , textAlign : 'center' } } > { msg . message } </ p > : null }
0 commit comments