@@ -8,9 +8,17 @@ import "./styles.css";
88export const messageReducer = ( state , action ) => {
99switch ( action . type ) {
1010case "RETWEET" :
11- // TODO: retweet
11+ return {
12+ ...state ,
13+ retweeted :! state . retweeted ,
14+ retweet_count :state . retweet_count + ( ! state . retweeted ?1 :- 1 )
15+ } ;
1216case "FAVORITE" :
13- // TODO: favorite
17+ return {
18+ ...state ,
19+ favorited :! state . favorited ,
20+ favorite_count :state . favorite_count + ( ! state . favorited ?1 :- 1 )
21+ } ;
1422default :
1523return state ;
1624}
@@ -51,30 +59,30 @@ export const Message = props => {
5159< div className = "Message_Body" > { text } </ div >
5260< div className = "Message_Footer" >
5361< Icon icon = "comment" title = "comment" />
54- < IconCountWrapper title = "retweet_count" count = { 0 } >
62+ < IconCountWrapper title = "retweet_count" count = { state . retweet_count } >
5563< IconButton
5664role = "retweet"
5765onClick = { ( ) => {
58- /* toggle retweet */
66+ dispatch ( { type : "RETWEET" } ) ;
5967} }
6068>
6169< Icon
6270icon = "retweet"
63- active = { false }
71+ active = { state . retweeted }
6472highlight = "rgb(23, 191, 99)"
6573/>
6674</ IconButton >
6775</ IconCountWrapper >
68- < IconCountWrapper title = "favorite_count" count = { 0 } >
76+ < IconCountWrapper title = "favorite_count" count = { state . favorite_count } >
6977< IconButton
7078role = "favorite"
7179onClick = { ( ) => {
72- /* toggle favorite */
80+ dispatch ( { type : "FAVORITE" } ) ;
7381} }
7482>
7583< Icon
7684icon = "favorite"
77- active = { false }
85+ active = { state . favorited }
7886highlight = "rgb(224, 36, 94)"
7987/>
8088</ IconButton >