Skip to content

Commit 0bc6e3e

Browse files
committed
implemented upvoting and downvoting of comments
1 parent 85a9683 commit 0bc6e3e

File tree

3 files changed

+80
-1
lines changed

3 files changed

+80
-1
lines changed

src/user/Admin/Tickets/TicketDiscussion/Discussion/Discussion.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import EditButton from "@material-ui/icons/EditOutlined";
1111
import CancelButton from "@material-ui/icons/ClearOutlined";
1212
import SendOutlinedIcon from "@material-ui/icons/SendOutlined";
1313
import userIcon2 from "../../../../../assets/images/userIcon2.jpg";
14+
import ThumbDownOutlinedIcon from "@material-ui/icons/ThumbDownOutlined";
15+
import ThumbUpAltOutlinedIcon from "@material-ui/icons/ThumbUpAltOutlined";
1416

1517
class Discussion extends Component {
1618
constructor(props) {
@@ -176,6 +178,30 @@ class Discussion extends Component {
176178
<ReactMarkdown source={ele.content} />
177179
</div>
178180
</div>
181+
<div className="comment-footer">
182+
<div
183+
className={
184+
ele.votes.upVotes.user.indexOf(currentUser.id) === -1
185+
? ""
186+
: "selected"
187+
}
188+
onClick={() => this.props.upVoteComment(ele._id)}
189+
>
190+
<ThumbUpAltOutlinedIcon />
191+
<span>{ele.votes.upVotes.user.length}</span>
192+
</div>
193+
<div
194+
className={
195+
ele.votes.downVotes.user.indexOf(currentUser.id) === -1
196+
? ""
197+
: "selected"
198+
}
199+
onClick={() => this.props.downVoteComment(ele._id)}
200+
>
201+
<ThumbDownOutlinedIcon />
202+
<span>{ele.votes.downVotes.user.length}</span>
203+
</div>
204+
</div>
179205
</div>
180206
</div>
181207
</div>

src/user/Admin/Tickets/TicketDiscussion/TicketDiscussion.scss

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,27 @@
140140
margin: 3px;
141141
/* identical to box height */
142142
}
143+
.comment-footer {
144+
display: flex;
145+
div {
146+
width: 50px;
147+
height: 40px;
148+
display: flex;
149+
align-items: center;
150+
span {
151+
margin-left: 5px;
152+
}
153+
svg {
154+
color: rgba(0,0,0,0.5);
155+
}
156+
}
157+
.selected{
158+
background-color: #F5F5F5;
159+
svg {
160+
color: #1a73e8;
161+
}
162+
}
163+
}
143164
small {
144165
font-family: Inter;
145166
font-style: normal;
@@ -240,7 +261,7 @@
240261
cursor: pointer;
241262
}
242263
}
243-
.dropdown-toggle{
264+
.dropdown-toggle {
244265
display: flex;
245266
align-items: center;
246267
}

src/user/Admin/Tickets/TicketDiscussion/TicketDiscussions.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,36 @@ class TicketDiscussions extends Component {
7676
}
7777
};
7878

79+
handleCommentUpvote = async (commentId) => {
80+
try {
81+
const newTicket = (
82+
await Axios.put(
83+
`${BASE_URL}/ticket/${this.state.ticket._id}/comment/${commentId}/upvote`
84+
)
85+
).data.ticket;
86+
this.setState({
87+
ticket: newTicket,
88+
});
89+
} catch (err) {
90+
console.log(err);
91+
}
92+
};
93+
94+
handleCommentDownvote = async (commentId) => {
95+
try {
96+
const newTicket = (
97+
await Axios.put(
98+
`${BASE_URL}/ticket/${this.state.ticket._id}/comment/${commentId}/downvote`
99+
)
100+
).data.ticket;
101+
this.setState({
102+
ticket: newTicket,
103+
});
104+
} catch (err) {
105+
console.log(err);
106+
}
107+
};
108+
79109
handleAddTag = async (tagName) => {
80110
if (this.state.ticket.tags.indexOf(tagName) !== -1) {
81111
toast.error("Tag already present");
@@ -143,6 +173,8 @@ class TicketDiscussions extends Component {
143173
sendComment={this.sendComment}
144174
editsAllowed={this.editsAllowed}
145175
updateTicket={this.handleUpdateTicket}
176+
upVoteComment={this.handleCommentUpvote}
177+
downVoteComment={this.handleCommentDownvote}
146178
/>
147179
)}
148180
{this.state.view === "history" && (

0 commit comments

Comments
 (0)