Без опису

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. import React, { Component } from 'react';
  2. import firebase from 'firebase'
  3. import { NavigationContainer } from '@react-navigation/native';
  4. import { createStackNavigator } from '@react-navigation/stack';
  5. import RegisterScreen from './screens/auth/RegisterScreen';
  6. import LoginScreen from './screens/auth/LoginScreen';
  7. import { firebaseConfig } from './config/firebaseConfig';
  8. import { Text, View } from 'react-native';
  9. import { styles } from './config/styles';
  10. import HomeScreen from './screens/main/Home_page';
  11. import { Provider} from 'react-redux'
  12. import { createStore, applyMiddleware } from 'redux';
  13. import rootReducer from './redux/reducers'
  14. import thunk from 'redux-thunk'
  15. import { connect } from 'react-redux'
  16. import { bindActionCreators } from 'redux'
  17. import { fetchUser } from './redux/actions/index'
  18. /*const seConfig = {
  19. apiKey: "AIzaSyDW-ABAQ3r_WR7C7WC_3VprL77NcAoitJI",
  20. authDomain: "freehand-d8ecd.firebaseapp.com",
  21. projectId: "freehand-d8ecd",
  22. storageBucket: "freehand-d8ecd.appspot.com",
  23. messagingSenderId: "48371388186",
  24. appId: "1:48371388186:web:9a5a4bf1218e17ac6326a3"
  25. };
  26. */
  27. // Initialize Firebase
  28. //const app = firebase.initializeApp(seConfig);
  29. if (firebase.apps.length === 0) {
  30. firebase.initializeApp(firebaseConfig)
  31. }
  32. const store = createStore(rootReducer, applyMiddleware(thunk));
  33. const Stack = createStackNavigator();
  34. export class App extends Component {
  35. constructor(props){
  36. super(props);
  37. this.state = {
  38. loaded: false,
  39. }
  40. }
  41. componentDidMount(){
  42. firebase.auth().onAuthStateChanged((user) => {
  43. if (!user){
  44. this.setState({
  45. loggedIn: false,
  46. loaded: true,
  47. })
  48. }
  49. else{
  50. this.setState({
  51. loggedIn: true,
  52. loaded: true,
  53. })
  54. }
  55. })
  56. }
  57. render() {
  58. const { loggedIn, loaded } = this.state
  59. if(!loaded){
  60. return(
  61. <View style={styles.regcontainer}>
  62. <Text>Hopper</Text>
  63. </View>
  64. );
  65. }
  66. if(!loggedIn){
  67. return (
  68. <NavigationContainer>
  69. <Stack.Navigator>
  70. <Stack.Screen name={" "} options={{headerShown: false}} component={LoginScreen}/>
  71. <Stack.Screen name={"Register"} options={{headerTransparent: true, headerTitle: " "}} component={RegisterScreen}/>
  72. </Stack.Navigator>
  73. </NavigationContainer>
  74. );
  75. }
  76. return(
  77. <Provider store={store}>
  78. <NavigationContainer>
  79. <Stack.Navigator initialRouteName="Home">
  80. <Stack.Screen name="Home" component={HomeScreen} />
  81. </Stack.Navigator>
  82. </NavigationContainer>
  83. </Provider>
  84. );
  85. }
  86. }
  87. const mapStateToProps = (store) => ({
  88. currentUser: store.userState.currentUser
  89. })
  90. const mapDispatchProps = (dispatch) => bindActionCreators({fetchUser}, dispatch);
  91. export default connect(mapStateToProps, mapDispatchProps)(App);