Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit132ce3d

Browse files
committed
solution: useReducer message
1 parent9448dd9 commit132ce3d

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

‎src/components/Message/useReducer.js‎

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

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp