@@ -16,7 +16,15 @@ export const Message = props => {
16
16
text
17
17
} = props ;
18
18
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
+ } ) ;
20
28
21
29
return (
22
30
< Card
@@ -35,30 +43,36 @@ export const Message = props => {
35
43
< div className = "Message_Body" > { text } </ div >
36
44
< div className = "Message_Footer" >
37
45
< Icon icon = "comment" title = "comment" />
38
- < IconCountWrapper title = "retweet_count" count = { 0 } >
46
+ < IconCountWrapper title = "retweet_count" count = { retweet . count } >
39
47
< IconButton
40
48
role = "retweet"
41
49
onClick = { ( ) => {
42
- /* toggle retweet locally */
50
+ toggleRetweet ( {
51
+ count :retweet . count + ( retweet . toggled ?- 1 :1 ) ,
52
+ toggled :! retweet . toggled
53
+ } ) ;
43
54
} }
44
55
>
45
56
< Icon
46
57
icon = "retweet"
47
- active = { false }
58
+ active = { retweet . toggled }
48
59
highlight = "rgb(23, 191, 99)"
49
60
/>
50
61
</ IconButton >
51
62
</ IconCountWrapper >
52
- < IconCountWrapper title = "favorite_count" count = { 0 } >
63
+ < IconCountWrapper title = "favorite_count" count = { favorite . count } >
53
64
< IconButton
54
65
role = "favorite"
55
66
onClick = { ( ) => {
56
- /* toggle favorite locally */
67
+ toggleFavorite ( {
68
+ count :favorite . count + ( favorite . toggled ?- 1 :1 ) ,
69
+ toggled :! favorite . toggled
70
+ } ) ;
57
71
} }
58
72
>
59
73
< Icon
60
74
icon = "favorite"
61
- active = { false }
75
+ active = { favorite . toggled }
62
76
highlight = "rgb(224, 36, 94)"
63
77
/>
64
78
</ IconButton >