@@ -17,13 +17,19 @@ import {
17
17
useSetProfileInSettings ,
18
18
useShowToastOnSuccessfulUpdating ,
19
19
} from "./profile-functions" ;
20
+ import { reallyGetAllPosts } from "../../../actions/getPostAction" ;
21
+ import { getThatProfileE } from "../../../actions/profileAction" ;
20
22
21
23
const Profile = ( {
22
24
profile,
23
25
uploadProfilePhoto,
24
26
loadProfile,
25
27
editProfile,
26
28
cleanProfile,
29
+ user,
30
+ post,
31
+ getThatProfileE,
32
+ reallyGetAllPosts,
27
33
} ) => {
28
34
const { isOpen, onOpen, onClose } = S . useDisclosure ( ) ;
29
35
const toast = S . useToast ( ) ;
@@ -35,16 +41,34 @@ const Profile = ({
35
41
const initialRef = React . useRef ( ) ;
36
42
const finalRef = React . useRef ( ) ;
37
43
38
- useLoadProfile ( loadProfile ) ;
44
+ useLoadProfile ( loadProfile , { getThatProfileE , reallyGetAllPosts } , user ) ;
39
45
useSetProfileInSettings ( profile , setProfileValues ) ;
40
46
useShowToastOnSuccessfulUpdating ( profile , onClose , cleanProfile , toast ) ;
41
47
48
+ let imgURL = "" ;
49
+ let name = "" ;
50
+ let bio = "" ;
51
+ let country = "" ;
52
+ if ( user . name === "user" && profile . profile . user ) {
53
+ imgURL = profile . profile . image ;
54
+ name = profile . profile . user . name ;
55
+ if ( ! isEmpty ( profile . profile ) ) {
56
+ bio = profile . profile . bio ;
57
+ country = profile . profile . country ;
58
+ }
59
+ } else if ( user . name !== "user" && profile . thatProfile ) {
60
+ imgURL = profile . thatProfile . image ;
61
+ name = user . name ;
62
+ bio = profile . thatProfile . bio ;
63
+ country = profile . thatProfile . country ;
64
+ }
65
+
42
66
return (
43
67
< React . Fragment >
44
68
< S . Flex py = "2rem" >
45
69
< S . Flex >
46
70
< S . Image
47
- src = { profile . profile && ` ${ profile . profile . image } ` }
71
+ src = { imgURL }
48
72
fallbackSrc = "https://i.ibb.co/RBT25fY/default-fallback-image.png"
49
73
style = { { width : "150px" , height : "150px" , borderRadius : "100%" } }
50
74
alt = "user"
@@ -53,9 +77,9 @@ const Profile = ({
53
77
< S . Flex mx = "3rem" flexDir = "column" py = "2rem" >
54
78
< S . Flex >
55
79
< S . Text >
56
- { profile . profile . user ? (
80
+ { profile . profile . user || profile . thatProfile ? (
57
81
< strong >
58
- < S . Text > { profile . profile . user . name } </ S . Text >
82
+ < S . Text > { name } </ S . Text >
59
83
</ strong >
60
84
) : (
61
85
< S . Skeleton height = "20px" w = "220px" my = "5px" > </ S . Skeleton >
@@ -64,30 +88,32 @@ const Profile = ({
64
88
</ S . Flex >
65
89
< S . Flex flexDir = "column" >
66
90
< S . Text >
67
- { ! isEmpty ( profile . profile ) ? (
68
- profile . profile . bio
91
+ { ! isEmpty ( profile . profile ) || profile . thatProfile ? (
92
+ < S . Text > { bio } </ S . Text >
69
93
) : (
70
94
< S . Skeleton height = "20px" w = "180px" mb = "5px" > </ S . Skeleton >
71
95
) }
72
96
</ S . Text >
73
97
< S . Text >
74
- { ! isEmpty ( profile . profile ) ? (
75
- profile . profile . country
98
+ { ! isEmpty ( profile . profile ) || profile . thatProfile ? (
99
+ < S . Text > { country } </ S . Text >
76
100
) : (
77
101
< S . Skeleton height = "20px" w = "180px" > </ S . Skeleton >
78
102
) }
79
103
</ S . Text >
80
104
</ S . Flex >
81
105
< S . Flex >
82
- < S . Button
83
- h = "30px"
84
- onClick = { onOpen }
85
- my = "5px"
86
- fontWeight = "normal"
87
- colorScheme = "blackAlpha"
88
- >
89
- Edit Profile
90
- </ S . Button >
106
+ { user . name === "user" && (
107
+ < S . Button
108
+ h = "30px"
109
+ onClick = { onOpen }
110
+ my = "5px"
111
+ fontWeight = "normal"
112
+ colorScheme = "blackAlpha"
113
+ >
114
+ Edit Profile
115
+ </ S . Button >
116
+ ) }
91
117
</ S . Flex >
92
118
</ S . Flex >
93
119
< S . Modal
@@ -164,6 +190,7 @@ const mapStateToProps = (state) => {
164
190
return {
165
191
auth : state . auth ,
166
192
profile : state . profile ,
193
+ post : state . post ,
167
194
} ;
168
195
} ;
169
196
@@ -173,4 +200,6 @@ export default connect(mapStateToProps, {
173
200
toggleBackdrop,
174
201
editProfile,
175
202
cleanProfile,
203
+ getThatProfileE,
204
+ reallyGetAllPosts,
176
205
} ) ( Profile ) ;
0 commit comments