This repository has been archived by the owner on Jul 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.tsx
103 lines (87 loc) · 3.83 KB
/
App.tsx
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
// AIzaSyDlRXMUhwmnCmDXpntaFkL66-vI6cMxWrY -- Google Maps API key
import 'react-native-gesture-handler'; //navigation stack, include at top
import { NavigationContainer } from '@react-navigation/native';
import { createStackNavigator } from '@react-navigation/stack';
import React, { useEffect } from 'react';
// FIREBASE (DATABASE)
// install firebase to root of project directory, $ npm install firebase
import { initializeApp } from "firebase/app";
import { getDatabase, ref, set, get, push, update, child, remove } from "firebase/database";
const firebaseConfig = {
apiKey: "AIzaSyBA3SGfDTI94WaJOxp_q0C2r3ypG6UCyj4",
authDomain: "cycle-savvy.firebaseapp.com",
databaseURL: "https://cycle-savvy-default-rtdb.asia-southeast1.firebasedatabase.app",
projectId: "cycle-savvy",
storageBucket: "cycle-savvy.appspot.com",
messagingSenderId: "537001875593",
appId: "1:537001875593:web:0d10ab8433ce7fb8e40e58",
measurementId: "G-3WGYQ5T50W"
};
// Initialize Firebase
const app = initializeApp(firebaseConfig);
export function writeUserData(mobile: string, password: string, questionType: string, answer: string) {
const db = getDatabase();
const reference = ref(db, 'users/' + mobile);
set(reference, {
password: password,
questionType : questionType,
answer: answer,
});
}
export function updateUserData(mobile: string, password: string) {
const db = getDatabase();
const userRef = ref(db, 'users/' + mobile);
update(userRef, {
password: password,
}).then(() => {
console.log(mobile, password);
console.log('Password updated successfully.');
}).catch((error) => {
console.error('Error updating password:', error);
});
}
//Component Forms
import Login from './Components/LoginForm/Login'
import ResetPw from './Components/ResetPwForm/ResetPw';
import Verification from './Components/VerificationForm/Verification';
import RegisterUser from './Components/RegisterUserForm/RegisterUser';
import Addresses from './Components/AddressesForm/Addresses';
import FAQ from './Components/FAQForm/FAQ';
import PrivacyConcerns from './Components/PrivacyForm/PrivacyConcerns';
import Map from './Components/MapForm/Map'; // CHANGE BACK TO MAP LATER THIS IS THE WRONG SCREEN
import ShareRide from './Components/ShareRideForm/ShareRide'
import ChangePw from './Components/ChangePwForm/ChangePw';
const Stack = createStackNavigator();
function App(): React.JSX.Element {
// IF WANT TO MAINTAIN USER ENTRIES, COMMENT OUT THIS FUNCTION
useEffect(() => { // DELETE ALL USER ENTRIES WHEN COMPONENT UNMOUNTS
return () => {
const db = getDatabase();
const reference = ref(db, 'users'); // REFERENCE TO USERS NODE TO CLEAR ENTRIES
remove(reference).then(() => {
console.log('Entries deleted successfully.');
})
.catch((error) => {
console.error('Error deleting entries:', error);
});
};
}, []);
return (
<>
<NavigationContainer>
<Stack.Navigator initialRouteName="Login">
<Stack.Screen name="Login" component={Login} options={{ headerShown: false }}/>
<Stack.Screen name="Register User" component={RegisterUser} />
<Stack.Screen name="Reset Password" component={ResetPw} />
<Stack.Screen name="Verification" component={Verification} options={{ headerShown: false }}/>
<Stack.Screen name="Saved Addresses" component={Addresses} />
<Stack.Screen name="FAQ" component={FAQ} />
<Stack.Screen name="Privacy Concerns" component={PrivacyConcerns} />
<Stack.Screen name="Change Password" component={ChangePw} />
<Stack.Screen name="Cycle Savvy" component={Map} options={{ headerShown: false }} />
</Stack.Navigator>
</NavigationContainer>
</>
);
}
export default App;