1
- import React from 'react' ;
1
+ import React , { useEffect , useState } from 'react' ;
2
2
import { View , Text , StyleSheet , TouchableOpacity } from 'react-native' ;
3
3
import Colors from '../../assets/colorConstants' ;
4
4
import { useFonts } from 'expo-font' ;
5
5
import { type RootStackParamList } from '../components/types' ;
6
6
import type { StackNavigationProp } from '@react-navigation/stack' ;
7
7
import { useNavigation } from '@react-navigation/native' ;
8
- export type StackNavigation = StackNavigationProp < RootStackParamList > ;
8
+ import { Entypo , FontAwesome , Feather } from '@expo/vector-icons' ;
9
+ import { getAuth , onAuthStateChanged } from 'firebase/auth' ;
10
+ import firebaseService from '../utilities/firebase' ;
11
+ import { UsersAPI } from '../APIs/UsersAPI' ;
12
+ import { type User } from '../models/User' ;
9
13
14
+ export type StackNavigation = StackNavigationProp < RootStackParamList > ;
10
15
export default function SettingsScreen ( ) : JSX . Element {
11
16
12
17
const navigation = useNavigation < StackNavigation > ( ) ;
13
18
19
+ const [ user , setUser ] = useState < User | undefined > ( undefined ) ;
20
+
21
+
14
22
const [ loaded ] = useFonts ( {
15
23
Montserrat : require ( '../../assets/fonts/MontserratThinRegular.ttf' ) ,
16
24
Josefin : require ( '../../assets/fonts/JosefinSansThinRegular.ttf' ) ,
17
25
} ) ;
18
26
27
+ const auth = getAuth ( ) ;
28
+ onAuthStateChanged ( auth , ( user ) => {
29
+ if ( user === null ) {
30
+ navigation . navigate ( 'Home' ) ;
31
+ }
32
+ } ) ;
33
+
34
+ useEffect ( ( ) => {
35
+ const fetchUserData = async ( ) : Promise < void > => {
36
+ void UsersAPI . GetLoggedInUser ( ) . then ( ( res ) => {
37
+ if ( res != null ) {
38
+ setUser ( res ) ;
39
+ }
40
+ } ) ;
41
+ } ;
42
+ void fetchUserData ( ) ;
43
+ } , [ ] ) ;
44
+
45
+ const handleLogOut = async ( ) :Promise < void > => {
46
+ try {
47
+ if ( user !== undefined || user != null ) {
48
+ await firebaseService . signOutUser ( ) ;
49
+ console . log ( "User has been logged out!" )
50
+ navigation . navigate ( 'Home' ) ;
51
+ }
52
+ } catch ( error ) {
53
+ console . error ( "Loggint Out Error:" , error )
54
+ }
55
+
56
+ }
57
+
58
+
19
59
if ( ! loaded ) {
20
60
return < > </ > ;
21
61
}
22
62
23
63
24
64
return (
25
65
< View style = { styles . container } >
26
- < TouchableOpacity style = { styles . buttons } onPress = { ( ) => { navigation . navigate ( 'UpdateProfile' ) ; } } >
27
- < Text style = { styles . labels } > Edit Profile </ Text >
28
- </ TouchableOpacity >
29
- < TouchableOpacity style = { styles . buttons } onPress = { ( ) => { navigation . navigate ( 'UpdatePassword' ) ; } } >
30
- < Text style = { styles . labels } > Update Password </ Text >
31
- </ TouchableOpacity >
32
- < TouchableOpacity style = { styles . buttons } onPress = { ( ) => { navigation . navigate ( 'UpdateHomeInfo' ) ; } } >
33
- < Text style = { styles . labels } > Update Home Info </ Text >
34
- </ TouchableOpacity >
35
- < TouchableOpacity style = { styles . buttons } >
36
- < Text style = { styles . labels } > Accessibility </ Text >
37
- </ TouchableOpacity >
66
+
67
+ < View style = { styles . buttonsContainer } >
68
+
69
+ < TouchableOpacity style = { styles . buttons } onPress = { ( ) => { navigation . navigate ( 'UpdateProfile' ) ; } } >
70
+ < FontAwesome name = "user-circle-o" size = { 24 } color = { Colors . DARKDARKGREEN } style = { styles . icon } />
71
+ < Text style = { styles . labels } > Edit Profile </ Text >
72
+ < Feather name = "edit-2" size = { 24 } color = { Colors . DARKDARKGREEN } style = { styles . nextButton } />
73
+ </ TouchableOpacity >
74
+
75
+ < TouchableOpacity style = { styles . buttons } onPress = { ( ) => { navigation . navigate ( 'UpdatePassword' ) ; } } >
76
+ < Entypo name = "key" size = { 24 } color = { Colors . DARKDARKGREEN } style = { styles . icon } />
77
+ < Text style = { styles . labels } > Update Password </ Text >
78
+ < Feather name = "edit-2" size = { 24 } color = { Colors . DARKDARKGREEN } style = { styles . nextButton } />
79
+ </ TouchableOpacity >
80
+
81
+ < TouchableOpacity style = { styles . buttons } onPress = { ( ) => { navigation . navigate ( 'UpdateHomeInfo' ) ; } } >
82
+ < Entypo name = "info-with-circle" size = { 24 } color = { Colors . DARKDARKGREEN } style = { styles . icon } />
83
+ < Text style = { styles . labels } > Update Home Info </ Text >
84
+ < Feather name = "edit-2" size = { 24 } color = { Colors . DARKDARKGREEN } style = { styles . nextButton } />
85
+ </ TouchableOpacity >
86
+
87
+ < TouchableOpacity style = { styles . buttons } >
88
+ < FontAwesome name = "universal-access" size = { 24 } color = { Colors . DARKDARKGREEN } style = { styles . icon } />
89
+ < Text style = { styles . labels } > Accessibility </ Text >
90
+ < Feather name = "edit-2" size = { 24 } color = { Colors . DARKDARKGREEN } style = { styles . nextButton } />
91
+ </ TouchableOpacity >
92
+
93
+ < TouchableOpacity style = { styles . logOutButton } onPress = { ( ) => { void handleLogOut ( ) } } >
94
+ < Text style = { styles . logOutLabel } > Log Out </ Text >
95
+ < Entypo name = "log-out" size = { 24 } color = { Colors . WHITE } style = { styles . nextButton } />
96
+ </ TouchableOpacity >
97
+
98
+ </ View >
99
+
38
100
</ View >
39
101
) ;
40
102
}
41
103
42
104
const styles = StyleSheet . create ( {
43
105
container : {
44
106
flex : 1 ,
45
- alignItems : 'center' ,
46
107
backgroundColor : Colors . LIGHTFGREEN ,
47
108
paddingTop : 40
109
+
110
+ } ,
111
+ buttonsContainer :{
112
+ alignItems : 'center' ,
48
113
} ,
49
114
buttons :{
50
115
width : '85%' ,
@@ -56,9 +121,31 @@ const styles = StyleSheet.create({
56
121
} ,
57
122
labels :{
58
123
fontWeight : '600' ,
59
- color : Colors . BLACK ,
124
+ color : Colors . DARKDARKGREEN ,
125
+ fontSize : 18 ,
126
+ marginLeft : '14%' ,
127
+ } ,
128
+ nextButton :{
129
+ position : 'absolute' ,
130
+ left : '85%' ,
131
+ } ,
132
+ logOutButton :{
133
+ width : '60%' ,
134
+ height : 56 ,
135
+ borderRadius : 15 ,
136
+ backgroundColor : Colors . DARKGREEN ,
137
+ top : '50%' ,
138
+ justifyContent : 'center' ,
139
+ } ,
140
+ logOutLabel :{
141
+ fontWeight : '600' ,
60
142
fontSize : 18 ,
61
143
marginLeft : 15 ,
144
+ color : Colors . WHITE
62
145
} ,
146
+ icon :{
147
+ position : 'absolute' ,
148
+ left : '5%' ,
149
+ }
63
150
64
151
} ) ;
0 commit comments