Skip to content
This repository was archived by the owner on Jul 16, 2024. It is now read-only.

Commit 7afc96e

Browse files
author
Sung Won Cho
committed
Require login for upvote
1 parent ac55557 commit 7afc96e

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

app/client/src/components/Post.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ class Post extends React.Component {
125125
onCancelVote={this.handleCancelVote}
126126
userUpvoted={userUpvoted}
127127
userDownvoted={userDownvoted}
128+
currentUser={currentUser}
128129
/>
129130
<div className="post-body-container">
130131
<div

app/client/src/components/PostVote.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
import React from "react";
22
import classnames from "classnames";
3+
import { withRouter } from "react-router-dom";
34

45
const PostVote = ({
56
post,
67
onVote,
78
onCancelVote,
89
userUpvoted,
9-
userDownvoted
10+
userDownvoted,
11+
currentUser,
12+
history
1013
}) => {
1114
let postScore = post.UpvoteCount - post.DownvoteCount;
1215
if (userUpvoted) {
@@ -23,6 +26,10 @@ const PostVote = ({
2326
className={classnames("vote-btn", { voted: userUpvoted })}
2427
onClick={e => {
2528
e.preventDefault();
29+
if (!currentUser) {
30+
history.push("/login");
31+
return;
32+
}
2633

2734
if (userUpvoted) {
2835
onCancelVote({ type: "Upvote" });
@@ -41,6 +48,10 @@ const PostVote = ({
4148
className={classnames("vote-btn", { voted: userDownvoted })}
4249
onClick={e => {
4350
e.preventDefault();
51+
if (!currentUser) {
52+
history.push("/login");
53+
return;
54+
}
4455

4556
if (userDownvoted) {
4657
onCancelVote({ type: "Downvote" });
@@ -55,4 +66,4 @@ const PostVote = ({
5566
</div>
5667
);
5768
};
58-
export default PostVote;
69+
export default withRouter(PostVote);

0 commit comments

Comments
 (0)