@@ -8,45 +8,45 @@ import {NavLink} from 'react-router-dom';
8
8
class Badges extends Component {
9
9
constructor ( props ) {
10
10
super ( props ) ;
11
- this . setActiveStory = this . setActiveStory . bind ( this ) ;
12
- this . clearActiveStory = this . clearActiveStory . bind ( this ) ;
11
+ this . setActiveBadge = this . setActiveBadge . bind ( this ) ;
12
+ this . clearActiveBadge = this . clearActiveBadge . bind ( this ) ;
13
13
this . prev = this . prev . bind ( this ) ;
14
14
this . next = this . next . bind ( this ) ;
15
- this . setStoryNextPrevIndex = this . setStoryNextPrevIndex . bind ( this ) ;
15
+ this . setBadgeNextPrevIndex = this . setBadgeNextPrevIndex . bind ( this ) ;
16
16
this . updatePopupActive = this . updatePopupActive . bind ( this ) ;
17
17
this . state = {
18
- activeStory : '' ,
19
- prevStory : '' ,
20
- nextStory : '' ,
18
+ activeBadge : '' ,
19
+ prevBadge : '' ,
20
+ nextBadge : '' ,
21
21
saluted : false ,
22
22
} ;
23
23
this . type = 'Badge' ;
24
24
}
25
25
26
- componentDidMount ( ) {
27
- this . setState ( {
28
- prevStory : this . props . stories [ 1 ] ,
29
- nextStory : this . props . stories [ 3 ]
30
- } ) ;
31
- }
32
-
33
- setActiveStory ( index ) {
34
- this . setState ( {
35
- activeStory : this . props . stories [ index ] ,
36
- activeSlideIndex : index
37
- } ) ;
38
- APIService . isSaluted ( this . type , this . props . stories [ index ] . id ) . then ( ( rsp ) => {
26
+ setActiveBadge ( index ) {
27
+ // Re-fetch the individual badge to increment the post views counter
28
+ this . props . fetchBadge ( index ) . then ( ( ) => {
29
+ this . setState ( {
30
+ saluted : false ,
31
+ } ) ;
32
+ return APIService . isSaluted ( this . type , this . props . badges [ index ] . id )
33
+ } ) . then ( ( rsp ) => {
39
34
this . setState ( { saluted : rsp . saluted } ) ;
40
- } ) ;
41
- this . setStoryNextPrevIndex ( index , this . props . stories . length ) ;
35
+ this . setBadgeNextPrevIndex ( index , this . props . badges . length ) ;
36
+ } ) . catch ( err => CommonService . showError ( err ) ) ;
42
37
}
43
38
44
39
/**
45
40
* salute post
46
41
*/
47
42
salutePost ( ) {
48
- APIService . salutePost ( this . type , this . state . activeStory . id ) . then ( ( ) => {
49
- this . setState ( { saluted : true } ) ;
43
+ APIService . salutePost ( this . type , this . state . activeBadge . id ) . then ( ( ) => {
44
+ const badge = this . state . activeBadge ;
45
+ badge . saluteCount = parseInt ( badge . shareCount , 10 ) + 1 ;
46
+ this . setState ( {
47
+ activeBadge : badge ,
48
+ saluted : true
49
+ } ) ;
50
50
CommonService . showSuccess ( `${ this . type } saluted successfully` ) ;
51
51
} ) . catch ( err => CommonService . showError ( err ) ) ;
52
52
}
@@ -55,42 +55,45 @@ class Badges extends Component {
55
55
* share post
56
56
*/
57
57
sharePost ( ) {
58
- APIService . sharePost ( this . type , this . state . activeStory . id ) . then ( ( ) => {
59
- this . setState ( { saluted : true } ) ;
58
+ APIService . sharePost ( this . type , this . state . activeBadge . id ) . then ( ( ) => {
59
+ const badge = this . state . activeBadge ;
60
+ badge . shareCount = parseInt ( badge . shareCount , 10 ) + 1 ;
61
+ this . setState ( {
62
+ activeBadge : badge
63
+ } ) ;
60
64
CommonService . showSuccess ( `${ this . type } shared successfully` ) ;
61
65
} ) . catch ( err => CommonService . showError ( err ) ) ;
62
66
}
63
67
64
- clearActiveStory ( ) {
68
+ clearActiveBadge ( ) {
65
69
this . setState ( {
66
- activeStory : ''
70
+ activeBadge : ''
67
71
} ) ;
68
72
}
69
73
70
74
next ( ) {
71
- const len = this . props . stories . length ;
75
+ const len = this . props . badges . length ;
72
76
let newIndex = ! ! this . state . activeSlideIndex ? this . state . activeSlideIndex : 0 ;
73
77
newIndex += 1 ;
74
78
newIndex = Math . min ( newIndex , len - 1 ) ;
75
- this . setStoryNextPrevIndex ( newIndex , len ) ;
79
+ this . setActiveBadge ( newIndex ) ;
76
80
}
77
81
78
82
prev ( ) {
79
- const len = this . props . stories . length ;
80
83
let newIndex = ! ! this . state . activeSlideIndex ? this . state . activeSlideIndex : 0 ;
81
84
newIndex -= 1 ;
82
85
newIndex = Math . max ( newIndex , 0 ) ;
83
- this . setStoryNextPrevIndex ( newIndex , len ) ;
86
+ this . setActiveBadge ( newIndex ) ;
84
87
}
85
88
86
- setStoryNextPrevIndex ( newIndex , len ) {
89
+ setBadgeNextPrevIndex ( newIndex , len ) {
87
90
const prevIndex = Math . max ( newIndex - 1 , 0 ) ;
88
91
const nextIndex = Math . min ( newIndex + 1 , len - 1 ) ;
89
92
this . setState ( {
90
- activeStory : this . props . stories [ newIndex ] ,
93
+ activeBadge : this . props . badges [ newIndex ] ,
91
94
activeSlideIndex : newIndex ,
92
- prevStory : this . props . stories [ prevIndex ] ,
93
- nextStory : this . props . stories [ nextIndex ]
95
+ prevBadge : this . props . badges [ prevIndex ] ,
96
+ nextBadge : this . props . badges [ nextIndex ]
94
97
} ) ;
95
98
}
96
99
@@ -99,9 +102,8 @@ class Badges extends Component {
99
102
}
100
103
101
104
render ( ) {
102
- const stories = this . props . stories ;
103
- const profileName = this . props . profileName ;
104
- const activeStory = this . state . activeStory ;
105
+ const { profileName, badges } = this . props ;
106
+ const activeBadge = this . state . activeBadge ;
105
107
106
108
return (
107
109
< div className = "collection-list-wrap collection-badges" >
@@ -111,15 +113,15 @@ class Badges extends Component {
111
113
< a className = "btn btn-badge btn-rt-1" onClick = { this . updatePopupActive } > < span className = "tx" > Add Badge</ span > </ a >
112
114
</ span >
113
115
114
- { ! this . state . activeStory
116
+ { ! activeBadge
115
117
? (
116
118
< div >
117
119
< div className = "viewport bd-collection-view" >
118
- { stories . map ( ( item , i ) => {
120
+ { badges . map ( ( item , i ) => {
119
121
return (
120
122
< div key = { i } className = "bd-collection-item-card-wrap" >
121
123
< div className = "collection-item-card con-centered con-badge"
122
- onClick = { ( ) => { this . setActiveStory ( i ) } } >
124
+ onClick = { ( ) => { this . setActiveBadge ( i ) } } >
123
125
< div className = "desc desc-md" >
124
126
< figure className = { "fig-badge " + item . badgeType . iconURL } />
125
127
</ div >
@@ -147,37 +149,37 @@ class Badges extends Component {
147
149
< div className = "viewport fullstory-view" >
148
150
< div className = "fullstory-slide" >
149
151
< div className = "fullstory-card fullstory-card-md alt" >
150
- < div className = "postedby" > Badge from < strong > { activeStory . createdBy . username } </ strong >
151
- < span className = "hide-md" > and < a > 5 other pepole </ a > </ span > </ div >
152
- < div className = "dateval" > { CommonService . getCreateTime ( activeStory ) } </ div >
152
+ < div className = "postedby" > Badge from < strong > { activeBadge . createdBy . username } </ strong >
153
+ < span className = "hide-md" > and < a > 5 other people </ a > </ span > </ div >
154
+ < div className = "dateval" > { CommonService . getCreateTime ( activeBadge ) } </ div >
153
155
< a className = "close"
154
- onClick = { this . clearActiveStory }
156
+ onClick = { this . clearActiveBadge }
155
157
> </ a >
156
- < a className = "flag" onClick = { ( ) => window . showProfileFlagPopUp ( 'Badge' , activeStory . id ) } > { '' } </ a >
158
+ < a className = "flag" onClick = { ( ) => window . showProfileFlagPopUp ( 'Badge' , activeBadge . id ) } > { '' } </ a >
157
159
< article className = "article centered article-badges" >
158
- < h3 className = "show-md" > { activeStory . title } </ h3 >
160
+ < h3 className = "show-md" > { activeBadge . title } </ h3 >
159
161
< div className = "fullstory" >
160
- < figure className = { "fig-badge bdg-md " + activeStory . badgeType . iconURL } > </ figure >
162
+ < figure className = { "fig-badge bdg-md " + activeBadge . badgeType . iconURL } > </ figure >
161
163
</ div >
162
- < h3 className = "hide-md" > { activeStory . badgeType . name } </ h3 >
164
+ < h3 className = "hide-md" > { activeBadge . badgeType . name } </ h3 >
163
165
< footer className = "article-footer alt" >
164
166
< div className = "col col-meta" >
165
167
< div className = "meta-gr" >
166
168
< h6 > Views</ h6 >
167
169
< div className = "meta-val reads" >
168
- { '1,333' }
170
+ { activeBadge . viewCount }
169
171
</ div >
170
172
</ div >
171
173
< div className = "meta-gr" >
172
174
< h6 > Salutes</ h6 >
173
175
< div className = "meta-val salutes" >
174
- { '469' }
176
+ { activeBadge . saluteCount }
175
177
</ div >
176
178
</ div >
177
179
< div className = "meta-gr" >
178
180
< h6 > Shares</ h6 >
179
181
< div className = "meta-val shares" >
180
- { '256' }
182
+ { activeBadge . shareCount }
181
183
</ div >
182
184
</ div >
183
185
</ div >
@@ -193,7 +195,7 @@ class Badges extends Component {
193
195
onClick = { this . prev }
194
196
> </ a > )
195
197
}
196
- { this . state . activeSlideIndex < this . props . stories . length - 1
198
+ { this . state . activeSlideIndex < this . props . badges . length - 1
197
199
&& ( < a className = "slide-arrow next"
198
200
onClick = { this . next }
199
201
> </ a > )
@@ -206,17 +208,17 @@ class Badges extends Component {
206
208
{ this . state . activeSlideIndex > 0
207
209
&&
208
210
( < div > < h5 > < a onClick = { this . prev } className = "prev" > Previous Badge</ a > </ h5 >
209
- < h4 > < a onClick = { this . prev } > { this . state . prevStory . badgeType . name } </ a > </ h4 > </ div > )
211
+ < h4 > < a onClick = { this . prev } > { this . state . prevBadge . badgeType . name } </ a > </ h4 > </ div > )
210
212
}
211
213
</ div >
212
214
< div className = "col col-btn show-md" >
213
215
< div className = "action" > < a className = "btn btn-more btn-md" > Load More Badges</ a > </ div >
214
216
</ div >
215
217
< div className = "col" >
216
- { this . state . activeSlideIndex < this . props . stories . length - 1
218
+ { this . state . activeSlideIndex < this . props . badges . length - 1
217
219
&&
218
220
( < div > < h5 > < a onClick = { this . next } className = "next" > Next Badge</ a > </ h5 >
219
- < h4 > < a onClick = { this . next } > { this . state . nextStory . badgeType . name } </ a > </ h4 > </ div > )
221
+ < h4 > < a onClick = { this . next } > { this . state . nextBadge . badgeType . name } </ a > </ h4 > </ div > )
220
222
}
221
223
</ div >
222
224
</ div >
@@ -230,6 +232,6 @@ class Badges extends Component {
230
232
231
233
Badges . propTypes = {
232
234
prop : PropTypes . object
233
- }
235
+ } ;
234
236
235
237
export default Badges ;
0 commit comments