File tree Expand file tree Collapse file tree 1 file changed +16
-8
lines changed Expand file tree Collapse file tree 1 file changed +16
-8
lines changed Original file line number Diff line number Diff line change @@ -8,9 +8,17 @@ import "./styles.css";
8
8
export const messageReducer = ( state , action ) => {
9
9
switch ( action . type ) {
10
10
case "RETWEET" :
11
- // TODO: retweet
11
+ return {
12
+ ...state ,
13
+ retweeted : ! state . retweeted ,
14
+ retweet_count : state . retweet_count + ( ! state . retweeted ? 1 : - 1 )
15
+ } ;
12
16
case "FAVORITE" :
13
- // TODO: favorite
17
+ return {
18
+ ...state ,
19
+ favorited : ! state . favorited ,
20
+ favorite_count : state . favorite_count + ( ! state . favorited ? 1 : - 1 )
21
+ } ;
14
22
default :
15
23
return state ;
16
24
}
@@ -51,30 +59,30 @@ export const Message = props => {
51
59
< div className = "Message_Body" > { text } </ div >
52
60
< div className = "Message_Footer" >
53
61
< Icon icon = "comment" title = "comment" />
54
- < IconCountWrapper title = "retweet_count" count = { 0 } >
62
+ < IconCountWrapper title = "retweet_count" count = { state . retweet_count } >
55
63
< IconButton
56
64
role = "retweet"
57
65
onClick = { ( ) => {
58
- /* toggle retweet */
66
+ dispatch ( { type : "RETWEET" } ) ;
59
67
} }
60
68
>
61
69
< Icon
62
70
icon = "retweet"
63
- active = { false }
71
+ active = { state . retweeted }
64
72
highlight = "rgb(23, 191, 99)"
65
73
/>
66
74
</ IconButton >
67
75
</ IconCountWrapper >
68
- < IconCountWrapper title = "favorite_count" count = { 0 } >
76
+ < IconCountWrapper title = "favorite_count" count = { state . favorite_count } >
69
77
< IconButton
70
78
role = "favorite"
71
79
onClick = { ( ) => {
72
- /* toggle favorite */
80
+ dispatch ( { type : "FAVORITE" } ) ;
73
81
} }
74
82
>
75
83
< Icon
76
84
icon = "favorite"
77
- active = { false }
85
+ active = { state . favorited }
78
86
highlight = "rgb(224, 36, 94)"
79
87
/>
80
88
</ IconButton >
You can’t perform that action at this time.
0 commit comments