diff --git a/dev-client/src/screens/LoginScreen.tsx b/dev-client/src/screens/LoginScreen.tsx index e3527cc91..727ef37b7 100644 --- a/dev-client/src/screens/LoginScreen.tsx +++ b/dev-client/src/screens/LoginScreen.tsx @@ -15,9 +15,10 @@ * along with this program. If not, see https://www.gnu.org/licenses/. */ -import {useCallback, useEffect} from 'react'; +import {useCallback, useEffect, useState} from 'react'; import {useTranslation} from 'react-i18next'; import {Platform, StyleSheet} from 'react-native'; +import {ActivityIndicator} from 'react-native-paper'; import {SafeAreaView} from 'react-native-safe-area-context'; import { @@ -28,7 +29,7 @@ import { import {Button} from 'native-base'; -import {setHasAccessTokenAsync} from 'terraso-client-shared/account/accountSlice'; +import {setHasToken} from 'terraso-client-shared/account/accountSlice'; import GoogleLogo from 'terraso-client-shared/assets/google.svg'; import MicrosoftLogo from 'terraso-client-shared/assets/microsoft.svg'; @@ -47,12 +48,51 @@ import {theme} from 'terraso-mobile-client/theme'; const showAppleAuth = Platform.OS === 'ios'; +type LoginButtonsProps = { + onPress: (provider: AuthProvider) => void; +}; + +const LoginButtons = ({onPress}: LoginButtonsProps) => { + const {t} = useTranslation(); + return ( + + + + {showAppleAuth ? ( + onPress('apple')} + /> + ) : ( + <> + )} + + ); +}; + export const LoginScreen = () => { const {t} = useTranslation(); const navigation = useNavigation(); const loggedIn = useSelector( state => state.account.currentUser.data !== null, ); + const [isLoading, setIsLoading] = useState(false); // note: we intentionally run this on every render, // so we can't accidentally get stuck on this view because @@ -60,14 +100,16 @@ export const LoginScreen = () => { const dispatch = useDispatch(); const onPress = useCallback( - (providerName: AuthProvider) => { - return () => { - auth(providerName) - .then(() => { - dispatch(setHasAccessTokenAsync()); - }) - .catch(e => console.error(e)); - }; + async (providerName: AuthProvider) => { + try { + setIsLoading(true); + await auth(providerName); + dispatch(setHasToken(true)); + } catch (e) { + console.error(e); + } finally { + setIsLoading(false); + } }, [dispatch], ); @@ -105,34 +147,14 @@ export const LoginScreen = () => { - - - - {showAppleAuth ? ( - - ) : ( - <> - )} - + {isLoading ? ( + + ) : ( + + )}