This repository was archived by the owner on May 30, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathApp.js
More file actions
131 lines (116 loc) · 3.05 KB
/
Copy pathApp.js
File metadata and controls
131 lines (116 loc) · 3.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
import React from "react";
import { View, StyleSheet } from "react-native";
import Login from "./components/LoginPage/Login";
import Fetcher from "./components/Fetcher";
import firebase from "./config/Firebase";
console.disableYellowBox = true;
const db = firebase.firestore();
var users = db.collection("users");
class App extends React.Component {
constructor(props) {
super(props);
this.state = {
user: null,
signUpMessage: ""
};
this.signUpUser = this.signUpUser.bind(this);
this.loginInUser = this.loginInUser.bind(this);
this.updateUser = this.updateUser.bind(this);
}
signUpUser = name => {
if (!name || name.length < 2 || !/^[a-zA-Z\s]*$/.test(name)) {
this.setState({ signUpMessage: "Invalid name" });
return;
}
var success = false;
users
.where("name", "==", name)
.get()
.then(function(querySnapshot) {
if (querySnapshot.empty) {
success = true;
}
})
.then(() => {
if (success) {
users.add({
name: name,
favorites: [],
following: []
});
this.setState({ signUpMessage: "Account created for " + name });
} else {
this.setState({ signUpMessage: name + " already exists" });
}
});
};
loginInUser = name => {
var success;
users
.where("name", "==", name)
.get()
.then(querySnapshot => {
if (querySnapshot.empty) {
this.setState({
signUpMessage:
"Invalid user: " + name + ". Sign up first to continue."
});
} else {
this.setState({ user: querySnapshot.docs[0].id });
}
});
};
updateUser(uid) {
this.setState({ user: uid });
}
// updateUserType(name) {
// users.add({
// name: name,
// favorites: [],
// following: []
// })
// .then(docRef => {
// this.setState({
// user: docRef.id,
// })
// })
// .catch(error => console.error("Error adding document: ", error))
// }
render() {
return (
<View style={styles.container}>
{this.state.user === null ? (
<Login
signUpUser={this.signUpUser}
loginInUser={this.loginInUser}
updateUser={this.updateUser}
signUpMessage={this.state.signUpMessage}
/>
) : (
<Fetcher user={this.state.user} />
)}
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
flexDirection: "column",
justifyContent: "center",
alignItems: "stretch"
}
});
export default App;
// import { createSwitchNavigator, createAppContainer } from 'react-navigation';
// import Loading from './components/Loading';
// import Login from './components/LoginPage/Login';
// import Main from './components/MainPage/Main';
// const App = createAppContainer(createSwitchNavigator({
// AuthLoading: Loading,
// Login: Login,
// Main: Main
// }, {
// initialRouteName: 'AuthLoading',
// }));
// export default App;