@@ -16,7 +16,15 @@ export const Message = props => {
1616 text
1717 } = props ;
1818
19- /* TODO: toggle retweet & favorite status & count on click */
19+ const [ retweet , toggleRetweet ] = React . useState ( {
20+ toggled : retweeted ,
21+ count : retweet_count
22+ } ) ;
23+
24+ const [ favorite , toggleFavorite ] = React . useState ( {
25+ toggled : favorited ,
26+ count : favorite_count
27+ } ) ;
2028
2129 return (
2230 < Card
@@ -35,30 +43,36 @@ export const Message = props => {
3543 < div className = "Message_Body" > { text } </ div >
3644 < div className = "Message_Footer" >
3745 < Icon icon = "comment" title = "comment" />
38- < IconCountWrapper title = "retweet_count" count = { 0 } >
46+ < IconCountWrapper title = "retweet_count" count = { retweet . count } >
3947 < IconButton
4048 role = "retweet"
4149 onClick = { ( ) => {
42- /* toggle retweet locally */
50+ toggleRetweet ( {
51+ count : retweet . count + ( retweet . toggled ? - 1 : 1 ) ,
52+ toggled : ! retweet . toggled
53+ } ) ;
4354 } }
4455 >
4556 < Icon
4657 icon = "retweet"
47- active = { false }
58+ active = { retweet . toggled }
4859 highlight = "rgb(23, 191, 99)"
4960 />
5061 </ IconButton >
5162 </ IconCountWrapper >
52- < IconCountWrapper title = "favorite_count" count = { 0 } >
63+ < IconCountWrapper title = "favorite_count" count = { favorite . count } >
5364 < IconButton
5465 role = "favorite"
5566 onClick = { ( ) => {
56- /* toggle favorite locally */
67+ toggleFavorite ( {
68+ count : favorite . count + ( favorite . toggled ? - 1 : 1 ) ,
69+ toggled : ! favorite . toggled
70+ } ) ;
5771 } }
5872 >
5973 < Icon
6074 icon = "favorite"
61- active = { false }
75+ active = { favorite . toggled }
6276 highlight = "rgb(224, 36, 94)"
6377 />
6478 </ IconButton >
0 commit comments