Brak opisu

App.js 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. import React, { Component } from 'react';
  2. import firebase from 'firebase'
  3. import thunk from 'redux-thunk';
  4. import { NavigationContainer } from '@react-navigation/native';
  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';
  9. import AvailabilityScreen from './screens/AvailabilityScreen';
  10. import MailScreen from './screens/MailScreen';
  11. //import RegisterScreen from './screens/RegisterScreen';
  12. import RegisterScreen from './screens/auth/RegisterScreen';
  13. //import LoginScreen from './screens/LoginScreen';
  14. import LoginScreen from './screens/auth/LoginScreen';
  15. // import HomeScreen from './screens/HomeScreen';
  16. //import Loading from './components/Loading';
  17. import Loading from './screens/main/Loading';
  18. import { firebaseConfig } from './config/firebaseConfig';
  19. import rootReducer from './redux/reducers'
  20. import HomeScreen from './screens/main/Home_page';
  21. import RoomScreen from './screens/main/RoomScreen';
  22. import Calendario from './screens/main/Calendar';
  23. import Time from './screens/main/StateTime';
  24. import Search from './screens/main/Search';
  25. if (firebase.apps.length === 0) {
  26. firebase.initializeApp(firebaseConfig)
  27. }
  28. const Stack = createStackNavigator();
  29. const Drawer = createDrawerNavigator();
  30. const store = createStore(rootReducer, applyMiddleware(thunk));
  31. export default class App extends Component {
  32. constructor(props){
  33. super(props);
  34. this.state = {
  35. loaded: false,
  36. }
  37. }
  38. componentDidMount(){
  39. firebase.auth().onAuthStateChanged((user) => {
  40. if (!user){
  41. this.setState({
  42. loggedIn: false,
  43. loaded: true,
  44. })
  45. }
  46. else{
  47. this.setState({
  48. loggedIn: true,
  49. loaded: true,
  50. })
  51. }
  52. });
  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. render() {
  61. const { loggedIn, loaded } = this.state
  62. if(!loaded){
  63. return(
  64. <Loading/>
  65. );
  66. }
  67. if(!loggedIn){
  68. return (
  69. <NavigationContainer>
  70. <Stack.Navigator>
  71. <Stack.Screen name={"Login"} options={{headerShown: false}} component={LoginScreen}/>
  72. <Stack.Screen name={"Register"} options={{headerTransparent: true, headerTitle: " "}} component={RegisterScreen}/>
  73. </Stack.Navigator>
  74. </NavigationContainer>
  75. );
  76. }
  77. return(
  78. <Provider store={store}>
  79. <NavigationContainer>
  80. <Stack.Navigator initialRouteName="Home">
  81. <Stack.Screen name="Home" options={{headerTransparent: true, headerTitle: " "}} component={HomeScreen} />
  82. <Stack.Screen name="Room" component={RoomScreen} options={({ route }) => ({ title: route.params.thread.name })} />
  83. <Stack.Screen name="Calendar" component={Calendario}/>
  84. <Stack.Screen name = "StateTime" component={Time}/>
  85. <Stack.Screen name = "Search" component={Search}/>
  86. </Stack.Navigator>
  87. </NavigationContainer>
  88. </Provider>
  89. );
  90. }
  91. }