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

Commit7a9ecd0

Browse files
committed
solution: useState message
1 parent38ee2a3 commit7a9ecd0

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

‎src/components/Message/useState.js

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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
<divclassName="Message_Body">{text}</div>
3644
<divclassName="Message_Footer">
3745
<Iconicon="comment"title="comment"/>
38-
<IconCountWrappertitle="retweet_count"count={0}>
46+
<IconCountWrappertitle="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-
<IconCountWrappertitle="favorite_count"count={0}>
63+
<IconCountWrappertitle="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

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp