Skip to content

Commit

Permalink
Merge pull request #4 from DiegoOTdC/feat-registerAndLogin
Browse files Browse the repository at this point in the history
Feat register and login
  • Loading branch information
DiegoOTdC authored Aug 18, 2020
2 parents 5fd2fb0 + 34db0d6 commit 12b3404
Show file tree
Hide file tree
Showing 13 changed files with 529 additions and 12 deletions.
24 changes: 18 additions & 6 deletions App.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,26 @@ import Camera from "./src/screens/Camera";
import Preview from "./src/screens/Preview";
import Recipes from "./src/screens/Recipes";
import RecipeDetails from "./src/screens/RecipeDetails";
import Register from "./src/screens/Register";
import Login from "./src/screens/Login";
import * as firebase from "firebase";
import { YellowBox } from "react-native";
import {
apiKey,
authDomain,
databaseUrl,
projectId,
storageBucket,
messagingSenderId,
} from "@env";

const firebaseConfig = {
apiKey: "AIzaSyAm0BbCJAo1vuJ-G_eS8pORPJX4N9MO7-E",
authDomain: "niles-tdms.firebaseapp.com",
databaseURL: "https://niles-tdms.firebaseio.com/",
projectId: "niles-tdms",
storageBucket: "gs://niles-tdms.appspot.com",
messagingSenderId: "221952632429",
apiKey: apiKey,
authDomain: authDomain,
databaseUrl: databaseUrl,
projectId: projectId,
storageBucket: storageBucket,
messagingSenderId: messagingSenderId,
};

if (!firebase.apps.length) {
Expand All @@ -33,6 +43,8 @@ function App() {
<Provider store={store}>
<NavigationContainer>
<Stack.Navigator screenOptions={{ headerShown: false }}>
<Stack.Screen name="Login" component={Login} />
<Stack.Screen name="Register" component={Register} />
<Stack.Screen name="HomeScreen" component={HomeScreen} />
<Stack.Screen name="BarcodeScanner" component={BarcodeScanner} />
<Stack.Screen name="Camera" component={Camera} />
Expand Down
1 change: 1 addition & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ module.exports = function (api) {
api.cache(true);
return {
presets: ["babel-preset-expo"],
plugins: ["module:react-native-dotenv"],
};
};
29 changes: 29 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 7 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
"dependencies": {
"@expo-google-fonts/alata": "^0.1.0",
"@expo-google-fonts/alfa-slab-one": "^0.1.0",
"@expo-google-fonts/great-vibes": "^0.1.0",
"@expo-google-fonts/inter": "^0.1.0",
"@expo-google-fonts/rochester": "^0.1.0",
"@react-native-community/masked-view": "0.1.10",
"@react-navigation/native": "^5.7.3",
"@react-navigation/stack": "^5.9.0",
Expand All @@ -20,17 +22,21 @@
"cloudinary-react": "^1.6.6",
"dotenv": "^8.2.0",
"expo": "~38.0.8",
"expo-barcode-scanner": "~8.2.1",
"expo-camera": "~8.3.1",
"expo-constants": "~9.1.1",
"expo-font": "~8.2.1",
"expo-image-picker": "~8.3.0",
"expo-network": "~2.2.1",
"expo-secure-store": "~9.0.1",
"expo-status-bar": "^1.0.2",
"firebase": "^7.17.2",
"react": "~16.11.0",
"react-dom": "~16.11.0",
"react-native": "https://github.com/expo/react-native/archive/sdk-38.0.2.tar.gz",
"react-native-gesture-handler": "~1.6.0",
"react-native-hyperlink": "0.0.19",
"react-native-keyboard-aware-scroll-view": "^0.9.2",
"react-native-reanimated": "~1.9.0",
"react-native-safe-area-context": "~3.0.7",
"react-native-screens": "~2.9.0",
Expand All @@ -39,8 +45,7 @@
"react-native-web": "~0.11.7",
"react-redux": "^7.2.1",
"redux": "^4.0.5",
"redux-thunk": "^2.3.0",
"expo-barcode-scanner": "~8.2.1"
"redux-thunk": "^2.3.0"
},
"devDependencies": {
"@babel/core": "^7.8.6",
Expand Down
1 change: 1 addition & 0 deletions src/colours/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export const lightGreen = "#C9EBB4";
export const green = "#b3d89c";
export const darkGreen = "#70B247";
export const budGreen = "#82B167";

export const lightBlue = "#57AFCA";
export const blue = "#3b7080";
Expand Down
175 changes: 175 additions & 0 deletions src/screens/Login/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
import React, { useState, useEffect } from "react";
import { useDispatch, useSelector } from "react-redux";
import { login } from "../../store/user/actions";
import { selectToken } from "../../store/user/selectors";
import {
Text,
View,
StyleSheet,
TextInput,
ActivityIndicator,
TouchableWithoutFeedback,
KeyboardAvoidingView,
Platform,
SafeAreaView,
Keyboard,
} from "react-native";
import { KeyboardAwareScrollView } from "react-native-keyboard-aware-scroll-view";
import { green, darkGreen, budGreen, brown, blue } from "../../colours";
import { AlfaSlabOne_400Regular } from "@expo-google-fonts/alfa-slab-one";
import { useFonts, Alata_400Regular } from "@expo-google-fonts/alata";
import { Rochester_400Regular } from "@expo-google-fonts/rochester";
import { GreatVibes_400Regular } from "@expo-google-fonts/great-vibes";

const alfa = "AlfaSlabOne_400Regular";
const alata = "Alata_400Regular";
const rochester = "Rochester_400Regular";
const greatVibes = "GreatVibes_400Regular";

export default function Login({ navigation }) {
const dispatch = useDispatch();
const [email, setEmail] = useState("");
const [password, setPassword] = useState("");

const token = useSelector(selectToken);

const [fontsLoaded] = useFonts({
AlfaSlabOne_400Regular,
Alata_400Regular,
Rochester_400Regular,
GreatVibes_400Regular,
});

function onPress(email, password) {
dispatch(login(email, password));
setEmail("");
setPassword("");
}

useEffect(() => {
console.log("what is in token?", token);
if (token !== null) {
navigation.navigate("HomeScreen");
}
}, [token, navigation]);

if (!fontsLoaded) {
return <ActivityIndicator />;
} else {
return (
<KeyboardAwareScrollView style={{ flex: 1, backgroundColor: green }}>
<TouchableWithoutFeedback onPress={Keyboard.dismiss}>
<View style={styles.login}>
<View
style={{
width: 350,
height: 350,
backgroundColor: brown,
borderRadius: 175,
marginTop: -10,
}}
></View>
<View
style={{
width: "70%",
marginTop: 30,
}}
>
<Text
style={{
textAlign: "center",
fontFamily: greatVibes,
color: blue,
fontSize: 75,
}}
>
Welcome
</Text>
</View>
<TextInput
style={[
styles.text,
{ backgroundColor: budGreen, paddingBottom: 3, marginTop: 25 },
]}
placeholder="email"
placeholderTextColor={green}
onChangeText={(text) => setEmail(text)}
value={email}
/>
<TextInput
style={[
styles.text,
{ backgroundColor: budGreen, paddingBottom: 3, marginTop: 20 },
]}
placeholder="password"
placeholderTextColor={green}
secureTextEntry={true}
onChangeText={(text) => setPassword(text)}
value={password}
/>
<TouchableWithoutFeedback onPress={() => onPress(email, password)}>
<Text
style={[
styles.text,
{ backgroundColor: brown, marginTop: 20, paddingTop: 5 },
]}
>
Login!
</Text>
</TouchableWithoutFeedback>
<View
style={{
flexDirection: "row",
width: "70%",
justifyContent: "center",
marginTop: 15,
}}
>
<Text
style={{
color: budGreen,
fontFamily: alata,
fontSize: 15,
marginRight: 15,
paddingTop: 5,
}}
>
Don't have an account?
</Text>
<TouchableWithoutFeedback
onPress={() => navigation.navigate("Register")}
>
<Text
style={{
color: brown,
fontFamily: alata,
fontSize: 20,
}}
>
Register
</Text>
</TouchableWithoutFeedback>
</View>
</View>
</TouchableWithoutFeedback>
</KeyboardAwareScrollView>
);
}
}

const styles = StyleSheet.create({
login: {
flex: 1,
flexDirection: "column",
alignItems: "center",
backgroundColor: green,
},
text: {
height: 60,
fontFamily: alata,
fontSize: 25,
color: green,
width: "70%",
textAlign: "center",
},
});
Loading

0 comments on commit 12b3404

Please sign in to comment.