1
1
import React from 'react' ;
2
+ import CurrentUserContext from './contexts/current-user/current-user.context' ;
2
3
import { Switch , Route , Redirect } from 'react-router-dom' ;
3
- import { connect } from 'react-redux' ;
4
- import { createStructuredSelector } from 'reselect' ;
5
-
6
4
import './App.css' ;
7
-
8
5
import HomePage from './pages/homepage/homepage.component' ;
9
6
import ShopPage from './pages/shop/shop.component' ;
10
7
import SignInAndSignUpPage from './pages/sign-in-and-sign-up/sign-in-and-sign-up.component' ;
11
8
import CheckoutPage from './pages/checkout/checkout.component' ;
12
-
13
9
import Header from './components/header/header.component' ;
14
-
15
10
import { auth , createUserProfileDocument } from './firebase/firebase.utils' ;
16
11
17
- import { setCurrentUser } from './redux/user/user.actions' ;
18
- import { selectCurrentUser } from './redux/user/user.selectors' ;
19
-
20
12
class App extends React . Component {
13
+
14
+ constructor ( ) {
15
+ super ( ) ;
16
+ this . state = {
17
+ currentUser : null
18
+ }
19
+ }
20
+
21
21
unsubscribeFromAuth = null ;
22
22
23
23
componentDidMount ( ) {
24
- const { setCurrentUser } = this . props ;
25
-
24
+ console . log ( "Estoy seteando el estado..." ) ;
26
25
this . unsubscribeFromAuth = auth . onAuthStateChanged ( async userAuth => {
27
26
if ( userAuth ) {
28
27
const userRef = await createUserProfileDocument ( userAuth ) ;
29
28
30
29
userRef . onSnapshot ( snapShot => {
31
- setCurrentUser ( {
30
+ this . setState ( { currentUser : {
32
31
id : snapShot . id ,
33
32
...snapShot . data ( )
34
- } ) ;
33
+ } } ) ;
35
34
} ) ;
36
35
}
37
36
38
- setCurrentUser ( userAuth ) ;
37
+ this . setState ( { currentUser : userAuth } ) ;
38
+ console . log ( "termine de setear el estado..." ) ;
39
39
} ) ;
40
40
}
41
41
@@ -44,9 +44,12 @@ class App extends React.Component {
44
44
}
45
45
46
46
render ( ) {
47
+ console . log ( "El valor de current user en APP.JS es : " , this . state . currentUser ) ;
47
48
return (
48
49
< div >
49
- < Header />
50
+ < CurrentUserContext . Provider value = { this . state . currentUser } >
51
+ < Header />
52
+ </ CurrentUserContext . Provider >
50
53
< Switch >
51
54
< Route exact path = '/' component = { HomePage } />
52
55
< Route path = '/shop' component = { ShopPage } />
@@ -55,7 +58,7 @@ class App extends React.Component {
55
58
exact
56
59
path = '/signin'
57
60
render = { ( ) =>
58
- this . props . currentUser ? (
61
+ this . state . currentUser ? (
59
62
< Redirect to = '/' />
60
63
) : (
61
64
< SignInAndSignUpPage />
@@ -68,15 +71,5 @@ class App extends React.Component {
68
71
}
69
72
}
70
73
71
- const mapStateToProps = createStructuredSelector ( {
72
- currentUser : selectCurrentUser
73
- } ) ;
74
-
75
- const mapDispatchToProps = dispatch => ( {
76
- setCurrentUser : user => dispatch ( setCurrentUser ( user ) )
77
- } ) ;
78
74
79
- export default connect (
80
- mapStateToProps ,
81
- mapDispatchToProps
82
- ) ( App ) ;
75
+ export default App ;
0 commit comments