@@ -5,11 +5,47 @@ import './profile.css'
5
5
import { connect } from 'react-redux' ;
6
6
import Navbar from '../Navbar/Navbar' ;
7
7
import PostWrapper from '../DisplayPost/Wrapper' ;
8
+ import { getProfile } from '../../actions/profileActions' ;
9
+ import { bindActionCreators } from 'redux' ;
10
+ import CircularProgress from '@material-ui/core/CircularProgress' ;
11
+
8
12
class Profile extends Component {
9
13
constructor ( props ) {
10
14
super ( props ) ;
15
+ this . state = { loading : true , profileData : [ ] , owner : "true" } ;
16
+ }
17
+
18
+ componentWillMount ( ) {
19
+ var profileName = this . props . location . pathname . split ( '/' ) . pop ( ) ;
20
+ console . log ( "mounting" , profileName )
21
+ if ( profileName == 'profile' )
22
+ profileName = this . props . userData . user_name ;
23
+
24
+ if ( profileName == this . props . userData . user_name ) {
25
+ this . setState ( this . setState ( { profileData : this . props . userData , loading : false } ) )
26
+ }
27
+ else {
28
+ let data = { profileName : profileName , jwt : this . props . jwt } ;
29
+ this . props . getProfile ( data ) ;
30
+ }
31
+ }
32
+
33
+
34
+ componentWillReceiveProps ( nextProps ) {
35
+ if ( this . props . location . pathname . split ( '/' ) . pop ( ) != 'profile' )
36
+ this . setState ( { loading : false , profileData : nextProps . currentProfile } ) ;
37
+ else
38
+ this . setState ( { loading : false , profileData : nextProps . userData } ) ;
11
39
}
40
+
12
41
render ( ) {
42
+ if ( this . state . loading ) {
43
+ return (
44
+ < div >
45
+ < CircularProgress size = { 200 } />
46
+ </ div >
47
+ ) ;
48
+ }
13
49
return (
14
50
< React . Fragment >
15
51
< Navbar />
@@ -20,25 +56,29 @@ class Profile extends Component {
20
56
< img src = { require ( '../../images/superman2.jpg' ) } width = "200px" alt = "profilepic" />
21
57
</ div >
22
58
< div className = "name" >
23
- < Typography variant = "title" component = "h1" > { this . props . userData . fname + " " + this . props . userData . lname } </ Typography >
24
- < Typography variant = "subheading" > { this . props . userData . details } </ Typography >
59
+ < Typography variant = "title" component = "h1" > { this . state . profileData . fname + " " + this . state . profileData . lname } </ Typography >
60
+ < Typography variant = "subheading" > { this . state . profileData . details } </ Typography >
25
61
</ div >
26
62
</ Paper >
27
63
{ /* <Typography variant="title" component="h1" className = "title descriptionHelper" >
28
64
Posts by the user
29
65
</Typography> */ }
30
66
< div >
31
- < PostWrapper type = "user" name = { this . props . userData . user_name } owner = "true" />
67
+ < PostWrapper type = "user" name = { this . state . profileData . user_name } owner = { this . state . owner } />
32
68
</ div >
33
69
</ React . Fragment >
34
70
)
35
71
}
36
72
}
37
73
38
- function mapStateToProps ( store ) {
39
- return { userData : store . userData . userData } ;
74
+ function mapDispatchToProps ( dispatch ) {
75
+ return bindActionCreators ( { getProfile } , dispatch ) ;
40
76
}
41
77
42
78
79
+ function mapStateToProps ( store ) {
80
+ console . log ( store . currentProfile ) ;
81
+ return { userData : store . userData . userData , currentProfile : store . currentProfile , jwt : store . userData . jwt } ;
82
+ }
43
83
44
- export default connect ( mapStateToProps ) ( Profile ) ;
84
+ export default connect ( mapStateToProps , mapDispatchToProps ) ( Profile ) ;
0 commit comments