Skip to content

Commit 1cdbe2b

Browse files
committed
Refactored files, added FB button, changed screen flow
1 parent c75bf73 commit 1cdbe2b

File tree

20 files changed

+273
-187
lines changed

20 files changed

+273
-187
lines changed

src/actions/actionTypes.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
exports.LOGIN_SUCCESS = "LOGIN: SUCCESS";
2+
exports.LOGOUT_SUCCESS = "LOGOUT: SUCCESS";

src/actions/authActions.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { LOGIN_SUCCESS, LOGOUT_SUCCESS } from "./actionTypes";
2+
import Expo from "expo";
3+
const getFBToken = Expo.Facebook.logInWithReadPermissionsAsync;
4+
5+
const loginAction = user => {
6+
return {
7+
type: LOGIN_SUCCESS,
8+
user: user
9+
};
10+
};
11+
12+
const logoutAction = () => {
13+
return {
14+
type: LOGOUT_SUCCESS
15+
};
16+
};
17+
18+
async function login() {
19+
const { type, token } = await getFBToken("235578963603256", {
20+
permissions: ["public_profile"]
21+
});
22+
if (type === "success") {
23+
// Get the user's name using Facebook's Graph API
24+
const response = await fetch(
25+
`https://graph.facebook.com/me?access_token=${token}`
26+
);
27+
user = await response.json();
28+
return loginAction(user);
29+
}
30+
}
31+
32+
function logout() {
33+
return logoutAction();
34+
}
35+
36+
module.exports = {
37+
login,
38+
loginAction,
39+
logout
40+
};

src/components/AuthButton.js

Lines changed: 0 additions & 28 deletions
This file was deleted.

src/components/FBLoginButton.js

Lines changed: 0 additions & 33 deletions
This file was deleted.
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import React, { StyleSheet } from "react-native";
2+
3+
module.exports = StyleSheet.create({
4+
container: {
5+
flex: 1,
6+
flexDirection: "row",
7+
justifyContent: "center",
8+
alignItems: "center"
9+
},
10+
11+
FBLoginButton: {
12+
flex: 1,
13+
flexDirection: "row",
14+
alignItems: "center",
15+
justifyContent: "center",
16+
17+
height: 30,
18+
width: 175,
19+
paddingLeft: 2,
20+
21+
backgroundColor: "rgb(66,93,174)",
22+
borderRadius: 3,
23+
borderWidth: 1,
24+
borderColor: "rgb(66,93,174)",
25+
26+
shadowColor: "#000000",
27+
shadowOpacity: 0.8,
28+
shadowRadius: 2,
29+
shadowOffset: {
30+
height: 1,
31+
width: 0
32+
}
33+
},
34+
FBLoginButtonText: {
35+
color: "white",
36+
fontWeight: "600",
37+
fontSize: 14.2
38+
},
39+
FBLoginButtonTextLoggedIn: {
40+
marginLeft: 5
41+
},
42+
FBLoginButtonTextLoggedOut: {
43+
marginLeft: 18
44+
},
45+
FBLogo: {
46+
position: "absolute",
47+
height: 14,
48+
width: 14,
49+
left: 7,
50+
top: 7
51+
}
52+
});
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import React, { PropTypes } from "react";
2+
import {
3+
Button,
4+
StyleSheet,
5+
Text,
6+
Image,
7+
View,
8+
TouchableHighlight
9+
} from "react-native";
10+
import { connect } from "react-redux";
11+
import { login, logout } from "../../actions/authActions";
12+
import * as styles from "./FBLoginButton.css";
13+
14+
const FBLoginButton = ({ style, login, logout, user }) =>
15+
<View style={style}>
16+
<TouchableHighlight
17+
style={styles.container}
18+
onPress={user ? logout : login}
19+
>
20+
<View style={styles.FBLoginButton}>
21+
<Image
22+
style={styles.FBLogo}
23+
source={require("./images/FB-f-Logo__white_144.png")}
24+
/>
25+
<Text
26+
style={[
27+
styles.FBLoginButtonText,
28+
user
29+
? styles.FBLoginButtonTextLoggedIn
30+
: styles.FBLoginButtonTextLoggedOut
31+
]}
32+
numberOfLines={1}
33+
>
34+
{user ? "Log Out" : "Login with Facebook"}
35+
</Text>
36+
</View>
37+
</TouchableHighlight>
38+
</View>;
39+
40+
const mapStateToProps = state => ({
41+
user: state.auth.user
42+
});
43+
44+
const mapDispatchToProps = dispatch => ({
45+
login: async () => dispatch(await login()),
46+
logout: () => dispatch(logout())
47+
});
48+
49+
export default connect(mapStateToProps, mapDispatchToProps)(FBLoginButton);
1.95 KB
Loading

src/components/LoginScreen.js

Lines changed: 0 additions & 41 deletions
This file was deleted.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import React, { StyleSheet } from "react-native";
2+
3+
module.exports = StyleSheet.create({
4+
container: {
5+
flex: 1,
6+
justifyContent: "center",
7+
alignItems: "center",
8+
backgroundColor: "#F5FCFF"
9+
},
10+
fbLogin: {
11+
flexDirection: "row",
12+
marginLeft: "5%",
13+
marginRight: "5%"
14+
}
15+
});
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import React, { PropTypes } from "react";
2+
import { Button, StyleSheet, Text, View } from "react-native";
3+
import FBLoginButton from "../FBLoginButton/FBLoginButton";
4+
import { loginAction } from "../../actions/authActions";
5+
import * as styles from "./LoginScreen.css";
6+
7+
const LoginScreen = ({ navigation }) =>
8+
<View style={styles.container}>
9+
<FBLoginButton style={styles.fbLogin} />
10+
</View>;
11+
12+
LoginScreen.propTypes = {
13+
navigation: PropTypes.object.isRequired
14+
};
15+
16+
LoginScreen.navigationOptions = {
17+
title: "Log In"
18+
};
19+
20+
export default LoginScreen;

0 commit comments

Comments
 (0)