aboutsummaryrefslogtreecommitdiffstats
path: root/components/Login.jsx
diff options
context:
space:
mode:
authorGravatar piotrruss <mail@pruss.it> 2022-05-22 18:11:30 +0100
committerGravatar piotrruss <mail@pruss.it> 2022-05-22 18:11:30 +0100
commit1173480fd93a56fa60333c01ffc70b67db82826a (patch)
tree9f4732cc671be49aece29d6bdfbcdc77b211dd67 /components/Login.jsx
parent994bc43d488eefc0ee39f39dd7fae5515322b17b (diff)
downloadnotes_mobile-1173480fd93a56fa60333c01ffc70b67db82826a.tar.gz
notes_mobile-1173480fd93a56fa60333c01ffc70b67db82826a.tar.bz2
notes_mobile-1173480fd93a56fa60333c01ffc70b67db82826a.zip
added loader
Diffstat (limited to 'components/Login.jsx')
-rw-r--r--components/Login.jsx74
1 files changed, 41 insertions, 33 deletions
diff --git a/components/Login.jsx b/components/Login.jsx
index db4b15b..1a6ef92 100644
--- a/components/Login.jsx
+++ b/components/Login.jsx
@@ -1,47 +1,55 @@
import { StyleSheet, Text, TextInput, Pressable, View } from 'react-native'
import { useState } from 'react'
import { handleLogin } from '../utils/helpers'
+import Loader from './Loader'
const Login = ({ setSession, showError }) => {
const [email, setEmail] = useState('');
const [password, setPassword] = useState('');
const disabled = (e, p) => !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e) || p.length < 6;
+ const [loading, setLoading ] = useState(false)
return (
<View style={styles.container}>
- <Text style={styles.title}>Login to Notes</Text>
- <Text style={styles.text}>Account can be created through apps.pruss.it website</Text>
- <TextInput
- style={styles.input}
- autoComplete="email"
- placeholder="Email"
- placeholderTextColor="#BBB"
- keyboardType="email-address"
- returnKeyType="next"
- autoComplete="email"
- textContentType="emailAddress"
- value={email}
- onChange={e => setEmail(e.nativeEvent.text.toLowerCase())}
- />
- <TextInput
- style={styles.input}
- autoComplete="password"
- placeholder="Password"
- placeholderTextColor="#BBB"
- returnKeyType="next"
- autoComplete="password-new"
- secureTextEntry={true}
- textContentType="newPassword"
- value={password}
- onChange={e => setPassword(e.nativeEvent.text)}
- />
- <Pressable
- onPress={() => handleLogin({ email, password, setSession, showError })}
- style={{...styles.button, opacity: disabled(email, password) ? .3 : 1}}
- disabled={disabled(email, password)}
- >
- <Text style={styles.buttonText}>Login</Text>
- </Pressable>
+ {loading
+ ? <Loader style={{ width: 100 }} text="Signing in..." />
+ : (
+ <>
+ <Text style={styles.title}>Login to Notes</Text>
+ <Text style={styles.text}>Account can be created through apps.pruss.it website</Text>
+ <TextInput
+ style={styles.input}
+ autoComplete="email"
+ placeholder="Email"
+ placeholderTextColor="#BBB"
+ keyboardType="email-address"
+ returnKeyType="next"
+ autoComplete="email"
+ textContentType="emailAddress"
+ value={email}
+ onChange={e => setEmail(e.nativeEvent.text.toLowerCase())}
+ />
+ <TextInput
+ style={styles.input}
+ autoComplete="password"
+ placeholder="Password"
+ placeholderTextColor="#BBB"
+ returnKeyType="next"
+ autoComplete="password-new"
+ secureTextEntry={true}
+ textContentType="newPassword"
+ value={password}
+ onChange={e => setPassword(e.nativeEvent.text)}
+ />
+ <Pressable
+ onPress={() => handleLogin({ email, password, setSession, setLoading, showError })}
+ style={{...styles.button, opacity: disabled(email, password) ? .3 : 1}}
+ disabled={disabled(email, password)}
+ >
+ <Text style={styles.buttonText}>Login</Text>
+ </Pressable>
+ </>
+ )}
</View>
);
};