|
@@ -0,0 +1,141 @@
|
|
1
|
+import React, { Component } from 'react';
|
|
2
|
+import { connect } from 'react-redux';
|
|
3
|
+import { bindActionCreators } from 'redux';
|
|
4
|
+import firebase from 'firebase';
|
|
5
|
+import { Text, View, ImageBackground } from 'react-native';
|
|
6
|
+import MaterialIcons from 'react-native-vector-icons/MaterialIcons';
|
|
7
|
+
|
|
8
|
+import { fetchUser } from '../redux/actions/index'
|
|
9
|
+import Loading from '../components/Loading'
|
|
10
|
+import { styles } from '../config/styles'
|
|
11
|
+
|
|
12
|
+export class HomeScreen extends Component {
|
|
13
|
+ constructor(props){
|
|
14
|
+ super(props);
|
|
15
|
+ this.state = {
|
|
16
|
+ interpreter: false,
|
|
17
|
+ };
|
|
18
|
+ this.onLogout = this.onLogout.bind(this)
|
|
19
|
+ };
|
|
20
|
+
|
|
21
|
+ componentDidMount(){
|
|
22
|
+ this.props.fetchUser();
|
|
23
|
+ firebase.firestore()
|
|
24
|
+ .collection("Interpreters")
|
|
25
|
+ .doc(firebase.auth().currentUser.uid)
|
|
26
|
+ .get()
|
|
27
|
+ .then((snapshot) => {
|
|
28
|
+ if(snapshot.exists){
|
|
29
|
+ this.setState({interpreter: true})
|
|
30
|
+ }
|
|
31
|
+ })
|
|
32
|
+ }
|
|
33
|
+
|
|
34
|
+ onLogout(){
|
|
35
|
+ firebase.auth().signOut();
|
|
36
|
+ }
|
|
37
|
+
|
|
38
|
+ render() {
|
|
39
|
+ const { currentUser } = this.props;
|
|
40
|
+
|
|
41
|
+ if(currentUser == undefined){
|
|
42
|
+ return <Loading/>
|
|
43
|
+ }
|
|
44
|
+ if(this.state.interpreter){
|
|
45
|
+ return(
|
|
46
|
+ <View style={styles.regcontainer}>
|
|
47
|
+ <ImageBackground style={styles.home} source={require("../assets/yellow-white.jpg")}>
|
|
48
|
+ <View style={styles.homeTopView}>
|
|
49
|
+ <MaterialIcons name='logout' size={30} color='dodgerblue' onPress={() => this.onLogout()}/>
|
|
50
|
+ <MaterialIcons name='event' size={30} color='dodgerblue' style={styles.homeIcon} onPress={() => this.props.navigation.navigate('Availability')}/>
|
|
51
|
+ <MaterialIcons name='mail' size={30} color='dodgerblue' onPress={() => this.props.navigation.navigate('Mail')}/>
|
|
52
|
+ </View>
|
|
53
|
+ </ImageBackground>
|
|
54
|
+ <View style={styles.regcontainer}></View>
|
|
55
|
+ </View>
|
|
56
|
+ );
|
|
57
|
+ }
|
|
58
|
+ else{
|
|
59
|
+ return(
|
|
60
|
+ <View style={styles.regcontainer}><Text>You are a user</Text></View>
|
|
61
|
+ );
|
|
62
|
+ }
|
|
63
|
+ }
|
|
64
|
+}
|
|
65
|
+
|
|
66
|
+const mapStateProps = (store) => ({currentUser: store.userState.currentUser})
|
|
67
|
+const mapDispatchProps = (dispatch) => bindActionCreators({fetchUser}, dispatch)
|
|
68
|
+export default connect(mapStateProps, mapDispatchProps)(HomeScreen)
|
|
69
|
+
|
|
70
|
+/*export default function HomeScreen({navigation}) {
|
|
71
|
+ const [threads, setThreads] = useState([]);
|
|
72
|
+ const [loading, setLoading] = useState(true);
|
|
73
|
+
|
|
74
|
+ useEffect(() => {
|
|
75
|
+
|
|
76
|
+ const fire = firebase.firestore()
|
|
77
|
+ .collection('THREADS')
|
|
78
|
+
|
|
79
|
+ .onSnapshot(querySnapshot => {
|
|
80
|
+ const threads = querySnapshot.docs.map(documentSnapshot => {
|
|
81
|
+ return{
|
|
82
|
+ _id:documentSnapshot.id,
|
|
83
|
+ name:'',
|
|
84
|
+ ...documentSnapshot.data()
|
|
85
|
+ };
|
|
86
|
+
|
|
87
|
+ });
|
|
88
|
+
|
|
89
|
+ setThreads(threads);
|
|
90
|
+
|
|
91
|
+ if(loading){
|
|
92
|
+ setLoading(false);
|
|
93
|
+ }
|
|
94
|
+
|
|
95
|
+ });
|
|
96
|
+
|
|
97
|
+ return () => fire();
|
|
98
|
+ }, []);
|
|
99
|
+
|
|
100
|
+ if (loading) {
|
|
101
|
+ return <Loading />;
|
|
102
|
+ }
|
|
103
|
+
|
|
104
|
+ return (
|
|
105
|
+ <View style={styles.container}>
|
|
106
|
+ <FlatList
|
|
107
|
+ data={threads}
|
|
108
|
+ keyExtractor = {item => item._id}
|
|
109
|
+ ItemSeparatorComponent={() => <Divider />}
|
|
110
|
+ renderItem = {({item}) => (
|
|
111
|
+
|
|
112
|
+ <TouchableOpacity
|
|
113
|
+ onPress={() => navigation.navigate('Room', {thread: item})}
|
|
114
|
+
|
|
115
|
+ >
|
|
116
|
+ <List.Item
|
|
117
|
+ title={item.name}
|
|
118
|
+ description='Item description'
|
|
119
|
+ titleNumberOfLines={1}
|
|
120
|
+ titleStyle={styles.listTitle}
|
|
121
|
+ descriptionStyle={styles.listDescription}
|
|
122
|
+ descriptionNumberOfLines={1}
|
|
123
|
+ />
|
|
124
|
+ </TouchableOpacity>
|
|
125
|
+ )}
|
|
126
|
+ />
|
|
127
|
+
|
|
128
|
+ <Button
|
|
129
|
+ title='Add Room'
|
|
130
|
+ onPress={() => navigation.navigate('Add')}
|
|
131
|
+ />
|
|
132
|
+
|
|
133
|
+ <Button
|
|
134
|
+ title ='Room'
|
|
135
|
+ onPress= {() => navigation.navigate('Room')}
|
|
136
|
+ />
|
|
137
|
+
|
|
138
|
+ </View>
|
|
139
|
+ );
|
|
140
|
+ }
|
|
141
|
+*/
|