1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- import React, { Component } from 'react';
- import firebase from 'firebase'
- import thunk from 'redux-thunk';
- import { NavigationContainer } from '@react-navigation/native';
- import { createStackNavigator } from '@react-navigation/stack';
- import { createDrawerNavigator } from '@react-navigation/drawer';
- import { Provider } from 'react-redux';
- import { createStore, applyMiddleware } from 'redux';
-
- import AvailabilityScreen from './screens/AvailabilityScreen';
- import MailScreen from './screens/MailScreen';
- import RegisterScreen from './screens/RegisterScreen';
- import LoginScreen from './screens/LoginScreen';
- import HomeScreen from './screens/HomeScreen';
- import Loading from './components/Loading';
- import { firebaseConfig } from './config/firebaseConfig';
- import rootReducer from './redux/reducers'
-
-
-
- if (firebase.apps.length === 0) {
- firebase.initializeApp(firebaseConfig)
- }
-
- const Stack = createStackNavigator();
- const Drawer = createDrawerNavigator();
- const store = createStore(rootReducer, applyMiddleware(thunk));
-
- export default class App extends Component {
- constructor(props){
- super(props);
- this.state = {
- loaded: false,
- }
- }
-
- componentDidMount(){
- firebase.auth().onAuthStateChanged((user) => {
- if (!user){
- this.setState({
- loggedIn: false,
- loaded: true,
- })
- }
- else{
- this.setState({
- loggedIn: true,
- loaded: true,
- })
- }
- });
- }
-
- createHomeStack = () =>
- <Stack.Navigator>
- <Stack.Screen name={"Home"} options={{headerShown: false}} component={HomeScreen}/>
- <Stack.Screen name={"Mail"} options={{ headerStatusBarHeight: 100, headerTransparent: true, headerBackTitle: " ", headerTitle: " "}} component={MailScreen}/>
- <Stack.Screen name={"Availability"} options={{ headerStatusBarHeight: 100, headerTransparent: true, headerBackTitle: " ", headerTitle: " "}} component={AvailabilityScreen}/>
- </Stack.Navigator>
-
- render() {
-
- const { loggedIn, loaded } = this.state
-
- if(!loaded){
- return(
- <Loading/>
- );
- }
-
- if(!loggedIn){
- return (
- <NavigationContainer>
- <Stack.Navigator>
- <Stack.Screen name={" "} options={{headerShown: false}} component={LoginScreen}/>
- <Stack.Screen name={"Register"} options={{headerTransparent: true, headerTitle: " "}} component={RegisterScreen}/>
- </Stack.Navigator>
- </NavigationContainer>
- );
- }
-
- return(
- <Provider store={store}>
- <NavigationContainer>
- <Drawer.Navigator>
- <Drawer.Screen name={" "} options={{drawerLabel: "Home", headerTransparent: true}} children={this.createHomeStack}/>
- </Drawer.Navigator>
- </NavigationContainer>
- </Provider>
- );
- }
- }
|