Quellcode durchsuchen

logout(inside HomeScreen) + files; install drawer navigation

Zander Cuz vor 3 Jahren
Ursprung
Commit
db4a512cef
4 geänderte Dateien mit 232 neuen und 22 gelöschten Zeilen
  1. 27
    22
      App.js
  2. 45
    0
      screens/AvailabilityScreen.js
  3. 141
    0
      screens/HomeScreen.js
  4. 19
    0
      screens/MailScreen.js

+ 27
- 22
App.js Datei anzeigen

@@ -1,30 +1,32 @@
1 1
 import React, { Component } from 'react';
2 2
 import firebase from 'firebase'
3
+import thunk from 'redux-thunk';
3 4
 import { NavigationContainer } from '@react-navigation/native';
4 5
 import { createStackNavigator } from '@react-navigation/stack';
6
+import { createDrawerNavigator } from '@react-navigation/drawer';
7
+import { Provider } from 'react-redux';
8
+import { createStore, applyMiddleware } from 'redux';
5 9
 
6
-import RegisterScreen from './screens/auth/RegisterScreen';
7
-import LoginScreen from './screens/auth/LoginScreen';
10
+import AvailabilityScreen from './screens/AvailabilityScreen';
11
+import MailScreen from './screens/MailScreen';
12
+import RegisterScreen from './screens/RegisterScreen';
13
+import LoginScreen from './screens/LoginScreen';
14
+import HomeScreen from './screens/HomeScreen';
15
+import Loading from './components/Loading';
8 16
 import { firebaseConfig } from './config/firebaseConfig';
9
-import { Text, View } from 'react-native';
10
-import { styles } from './config/styles';
11
-
12
-import HomeScreen from './screens/main/Home_page';
13
-import { Provider} from 'react-redux'
14
-import { createStore, applyMiddleware } from 'redux';
15 17
 import rootReducer from './redux/reducers'
16
-import thunk from 'redux-thunk'
18
+
17 19
 
18 20
 
19 21
 if (firebase.apps.length === 0) {
20 22
   firebase.initializeApp(firebaseConfig)
21 23
 }
22 24
 
23
-const store = createStore(rootReducer, applyMiddleware(thunk));
24
-
25 25
 const Stack = createStackNavigator();
26
+const Drawer = createDrawerNavigator();
27
+const store = createStore(rootReducer, applyMiddleware(thunk));
26 28
 
27
-export class App extends Component {
29
+export default class App extends Component {
28 30
   constructor(props){
29 31
     super(props);
30 32
     this.state = {
@@ -46,18 +48,23 @@ export class App extends Component {
46 48
           loaded: true,
47 49
         })
48 50
       }
49
-    })
51
+    });
50 52
   }
51 53
 
54
+  createHomeStack = () => 
55
+    <Stack.Navigator>
56
+      <Stack.Screen name={"Home"} options={{headerShown: false}} component={HomeScreen}/>
57
+      <Stack.Screen name={"Mail"} options={{ headerStatusBarHeight: 100, headerTransparent: true, headerBackTitle: " ", headerTitle: " "}} component={MailScreen}/>
58
+      <Stack.Screen name={"Availability"} options={{ headerStatusBarHeight: 100, headerTransparent: true, headerBackTitle: " ", headerTitle: " "}} component={AvailabilityScreen}/>
59
+    </Stack.Navigator>
60
+  
52 61
   render() {
53 62
 
54 63
     const { loggedIn, loaded } = this.state
55 64
 
56 65
     if(!loaded){
57 66
       return(
58
-        <View style={styles.regcontainer}>
59
-          <Text>Hopper</Text>
60
-        </View>
67
+        <Loading/>
61 68
       );
62 69
     }
63 70
 
@@ -75,13 +82,11 @@ export class App extends Component {
75 82
     return(
76 83
       <Provider store={store}>
77 84
         <NavigationContainer>
78
-          <Stack.Navigator initialRouteName="Home">
79
-            <Stack.Screen name="Home" component={HomeScreen} />
80
-          </Stack.Navigator>
85
+          <Drawer.Navigator>
86
+            <Drawer.Screen name={" "} options={{drawerLabel: "Home", headerTransparent: true}} children={this.createHomeStack}/>
87
+          </Drawer.Navigator>
81 88
         </NavigationContainer>
82 89
       </Provider>
83 90
     );
84 91
   }
85
-}
86
-
87
-export default App
92
+}

+ 45
- 0
screens/AvailabilityScreen.js Datei anzeigen

@@ -0,0 +1,45 @@
1
+import React, { Component } from "react";
2
+import { TextInput, TouchableWithoutFeedback, Keyboard, ImageBackground, Image, View } from "react-native";
3
+import firebase from "firebase";
4
+import { Picker } from "@react-native-picker/picker";
5
+
6
+import { styles } from "../config/styles";
7
+import CustomButton from "../components/CustomButton";
8
+
9
+
10
+export default class AvailabilityScreen extends Component {
11
+    constructor(props) {
12
+        super(props);
13
+        this.state = {
14
+            face_to_face: false,
15
+            online: false,
16
+            multiple: false,
17
+            one_on_one: false,
18
+            spanish: false,
19
+            english: false,
20
+            language: 0,
21
+        };
22
+    };
23
+
24
+    render() {  
25
+        return (
26
+            <View style={styles.regcontainer}>
27
+                <Picker style={styles.picker} selectedValue={this.state.language} onValueChange={(itemValue,itemIndex) => {
28
+                    this.setState({language: itemValue})
29
+                    if(itemValue === 0){
30
+                        this.setState({english: true, spanish: false});
31
+                    }
32
+                    else if(itemValue === 1){
33
+                        this.setState({english: false, spanish: true});
34
+                    }
35
+                    else{
36
+                        this.setState({english: true, spanish: true});
37
+                    }}}>
38
+                        <Picker.Item label="English" value={0}/>
39
+                        <Picker.Item label="Spanish" value={1}/>
40
+                        <Picker.Item label="Both" value={2}/>
41
+                    </Picker>
42
+            </View>
43
+        );
44
+    }
45
+}

+ 141
- 0
screens/HomeScreen.js Datei anzeigen

@@ -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
+*/

+ 19
- 0
screens/MailScreen.js Datei anzeigen

@@ -0,0 +1,19 @@
1
+import React, { Component } from "react";
2
+import { View, Text } from "react-native";
3
+
4
+import { styles } from "../config/styles";
5
+
6
+export default class MailScreen extends Component {
7
+    constructor(props) {
8
+        super(props);
9
+        this.state = {
10
+        };
11
+    };
12
+
13
+    render() {
14
+        
15
+        return (
16
+            <View style={styles.regcontainer}><Text>This is Mail</Text></View>
17
+        );
18
+    }
19
+}