Skip to content
Snippets Groups Projects
Commit 4328cc70 authored by Lukas Mauß's avatar Lukas Mauß
Browse files

Add voting functions to components

parent 453cfffe
No related merge requests found
...@@ -19,9 +19,9 @@ export class CommentListComponent implements OnInit { ...@@ -19,9 +19,9 @@ export class CommentListComponent implements OnInit {
filteredComments: Comment[]; filteredComments: Comment[];
constructor(private commentService: CommentService, constructor(private commentService: CommentService,
private translateService: TranslateService, private translateService: TranslateService,
protected langService: LanguageService, protected langService: LanguageService,
private rxStompService: RxStompService) { private rxStompService: RxStompService) {
langService.langEmitter.subscribe(lang => translateService.use(lang)); langService.langEmitter.subscribe(lang => translateService.use(lang));
} }
...@@ -51,28 +51,36 @@ export class CommentListComponent implements OnInit { ...@@ -51,28 +51,36 @@ export class CommentListComponent implements OnInit {
parseIncomingMessage(message: Message) { parseIncomingMessage(message: Message) {
const msg = JSON.parse(message.body); const msg = JSON.parse(message.body);
const payload = msg.payload; const payload = msg.payload;
if (msg.type === 'CommentCreated') { switch (msg.type) {
const c = new Comment(); case 'CommentCreated':
c.roomId = this.roomId; const c = new Comment();
c.body = payload.body; c.roomId = this.roomId;
c.id = payload.id; c.body = payload.body;
c.creationTimestamp = payload.timestamp; c.id = payload.id;
this.comments = this.comments.concat(c); c.creationTimestamp = payload.timestamp;
} else if (msg.type === 'CommentPatched') { this.comments = this.comments.concat(c);
break;
case 'CommentPatched':
for (let i = 0; i < this.comments.length; i++) { for (let i = 0; i < this.comments.length; i++) {
if (payload.id === this.comments[i].id) { if (payload.id === this.comments[i].id) {
for (const [key, value] of Object.entries(payload.changes)) { for (const [key, value] of Object.entries(payload.changes)) {
switch (key) { switch (key) {
case 'read': this.comments[i].read = <boolean>value; case 'read':
break; this.comments[i].read = <boolean>value;
case 'correct' : this.comments[i].correct = <boolean>value; break;
break; case 'correct' :
case 'favorite' : this.comments[i].favorite = <boolean>value; this.comments[i].correct = <boolean>value;
break; break;
case 'favorite' :
this.comments[i].favorite = <boolean>value;
break;
case 'score' :
this.comments[i].score = <number>value;
break;
} }
} }
} }
} }
} }
} }
} }
......
...@@ -51,6 +51,14 @@ export class CommentComponent implements OnInit { ...@@ -51,6 +51,14 @@ export class CommentComponent implements OnInit {
this.comment = this.wsCommentService.toggleFavorite(comment); this.comment = this.wsCommentService.toggleFavorite(comment);
} }
voteUp(comment: Comment): void {
this.wsCommentService.voteUp(comment);
}
voteDown(comment: Comment): void {
this.wsCommentService.voteDown(comment);
}
delete(comment: Comment): void { delete(comment: Comment): void {
this.commentService.deleteComment(comment.id).subscribe(room => { this.commentService.deleteComment(comment.id).subscribe(room => {
this.notification.show(`Comment '${comment.body}' successfully deleted.`); this.notification.show(`Comment '${comment.body}' successfully deleted.`);
......
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