Skip to content

Commit

Permalink
loader at login and register added
Browse files Browse the repository at this point in the history
  • Loading branch information
Deepak-Sangle committed Dec 13, 2023
1 parent d8867d9 commit f965af6
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 2 deletions.
5 changes: 4 additions & 1 deletion mobile-client/src/screens/HomePage.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
TouchableOpacity,
Easing,
Keyboard,
ActivityIndicator,
ScrollView,
ImageBackground,
} from "react-native";
Expand Down Expand Up @@ -304,7 +305,9 @@ const HomePage = ({ route, navigation }) => {
{events!==undefined && <RenderAllEntries />}
</View>
</View>}

{selectedTab===1 && secondLoading && <View style={styles.loadingView}>
<ActivityIndicator size="large" color={PRIMARY_COLOR} />
</View>}

</ScrollView>

Expand Down
9 changes: 8 additions & 1 deletion mobile-client/src/screens/Login.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
import React, { Component, useState, useRef } from 'react';
import { Linking, View, Text, StyleSheet, TextInput, Button, TouchableHighlight, TouchableOpacity, Image, ScrollView, ImageBackground } from 'react-native';
import { Linking, View, Text, StyleSheet, ActivityIndicator, TextInput, Button, TouchableHighlight, TouchableOpacity, Image, ScrollView, ImageBackground } from 'react-native';
import styles from '../styles/login';

const Login = ({navigation}) => {

const [name, setName] = useState('');
const [passcode, setPasscode] = useState(['','','','']);
const [loading, setLoading] = useState(false);

const {BASE_URI, PRIMARY_COLOR} = require('../constant.js');

const passcodeRefs = Array.from({ length: 4 }, () => useRef(null));

const login = async () => {
try{
setLoading(true);
const res = await fetch(`${BASE_URI}/login`, {
method : 'POST',
headers: {
Expand All @@ -26,6 +28,7 @@ const Login = ({navigation}) => {
})
});
const data = await res.json();
setLoading(false);
if(data.success === true){
navigation.navigate('/', {state : data.data});
}
Expand All @@ -35,6 +38,7 @@ const Login = ({navigation}) => {
}
catch(e){
alert(e.response.data.message);
setLoading(false);
}
}

Expand Down Expand Up @@ -117,6 +121,9 @@ const Login = ({navigation}) => {

</View>
</ImageBackground>
{loading && <View style={styles.loadingView}>
<ActivityIndicator size="large" color={PRIMARY_COLOR} />
</View>}
</ScrollView>
)
}
Expand Down
11 changes: 11 additions & 0 deletions mobile-client/src/screens/Registration.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
TextInput,
Button,
TouchableHighlight,
ActivityIndicator,
TouchableOpacity,
Image,
ScrollView,
Expand All @@ -22,6 +23,7 @@ const Registration = ({ navigation }) => {
const [isAvailable, setIsAvailable] = useState(true);
const [usersNames, setUsersNames] = useState([]);
const [name, setName] = useState("");
const [loading, setLoading] = useState(false);
const [passcode, setPasscode] = useState("");
const [cpasscode, setCpasscode] = useState("");

Expand All @@ -35,6 +37,7 @@ const Registration = ({ navigation }) => {
alert("You have to make your password of exactly 4 digit long");
return;
}
setLoading(true);
const res = await fetch(`${BASE_URI}/register`, {
method: "POST",
credentials : 'include',
Expand All @@ -49,12 +52,14 @@ const Registration = ({ navigation }) => {
}),
});
const data = await res.json();
setLoading(false);
if (data.success === true) {
navigation.navigate("/login");
} else {
alert(data.message);
}
} catch (e) {
setLoading(false);
alert(e.response.data.message);
}
};
Expand All @@ -66,6 +71,9 @@ const Registration = ({ navigation }) => {
return;
} else if (isAvailable && name !== "") {
saveName();
} else if (!isAvailable) {
alert("Username is not available");
return;
}
}

Expand Down Expand Up @@ -194,6 +202,9 @@ const Registration = ({ navigation }) => {
</View>
</View>
</ImageBackground>
{loading && <View style={styles.loadingView}>
<ActivityIndicator size="large" color={PRIMARY_COLOR} />
</View>}
</ScrollView>
);
};
Expand Down
7 changes: 7 additions & 0 deletions mobile-client/src/styles/home.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ const styles = StyleSheet.create({
entry: {
textAlign: "center"
},
loadingView : {
transform : "scale(1.5)",
display : "flex",
height : HEIGHT,
justifyContent : "center",
alignItems : "center"
},
entryDate: {
margin: 0,
display : "flex",
Expand Down
12 changes: 12 additions & 0 deletions mobile-client/src/styles/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,18 @@ const styles = StyleSheet.create({
marginBottom : 10,
fontFamily: "Inter_900Black"
},
loadingView : {
transform : 'scale(1.5)',
position: 'absolute',
left: 0,
right: 0,
top: 0,
backgroundColor : "black",
opacity : 0.7,
bottom: 0,
alignItems: 'center',
justifyContent: 'center'
},
description: {
fontFamily: "Nunito_400Regular",
color : PRIMARY_COLOR,
Expand Down

0 comments on commit f965af6

Please sign in to comment.