Skip to content
Snippets Groups Projects
Commit 97833466 authored by Tom Käsler's avatar Tom Käsler
Browse files

Add ResetVote functionality

Send ResetVote command on reclicking voting buttons
parent 704e5e45
1 merge request!202Add ResetVote functionality
Pipeline #26973 passed with stages
in 5 minutes and 46 seconds
......@@ -95,6 +95,10 @@ export class CommentComponent implements OnInit {
if (this.hasVoted !== 1) {
this.wsCommentService.voteUp(comment, userId);
this.hasVoted = 1;
} else {
this.wsCommentService.resetVote(comment, userId);
this.hasVoted = 0;
this.startAnimation(0);
}
}
......@@ -103,6 +107,10 @@ export class CommentComponent implements OnInit {
if (this.hasVoted !== -1) {
this.wsCommentService.voteDown(comment, userId);
this.hasVoted = -1;
} else {
this.wsCommentService.resetVote(comment, userId);
this.hasVoted = 0;
this.startAnimation(0);
}
}
......
export class ResetVote {
type: string;
payload: {
userId: string;
commentId: string;
};
constructor(userId: string, commentId: string) {
this.type = 'ResetVote';
this.payload = {
userId: userId,
commentId: commentId
};
}
}
......@@ -7,6 +7,7 @@ import { HighlightComment } from '../../models/messages/highlight-comment';
import { TSMap } from 'typescript-map';
import { UpVote } from '../../models/messages/up-vote';
import { DownVote } from '../../models/messages/down-vote';
import { ResetVote } from '../../models/messages/reset-vote';
import { Observable } from 'rxjs';
import { IMessage } from '@stomp/stompjs';
......@@ -58,6 +59,11 @@ export class WsCommentServiceService {
this.wsConnector.send(`/queue/vote.command.downvote`, JSON.stringify(message));
}
resetVote(comment: Comment, userId: string): void {
const message = new ResetVote(userId, comment.id);
this.wsConnector.send(`/queue/vote.command.resetvote`, JSON.stringify(message));
}
private patchComment(comment: Comment, changes: TSMap<string, any>): void {
const message = new PatchComment(comment.id, changes);
this.wsConnector.send(`/queue/comment.command.patch`, JSON.stringify(message));
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment