51 lines
1.4 KiB
TypeScript
51 lines
1.4 KiB
TypeScript
import { Component, OnInit, Input } from '@angular/core';
|
|
import { VoteService } from '../../services/vote.service';
|
|
import { CommentService } from '../../services/comment.service';
|
|
|
|
@Component({
|
|
selector: 'ui-comment',
|
|
templateUrl: './comment.ui.html',
|
|
styleUrls: [ './comment.ui.scss' ]
|
|
})
|
|
export class UiComment implements OnInit {
|
|
|
|
@Input() comment: any;
|
|
@Input() change: Function;
|
|
|
|
boundReplyCallback: Function;
|
|
|
|
constructor(private commentService: CommentService, private voteService: VoteService) { }
|
|
|
|
ngOnInit(): void {
|
|
this.commentService.countParent(this.comment.target, this.comment.id).subscribe((data) => {
|
|
this.comment.metadata.comments = +data;
|
|
});
|
|
|
|
this.boundReplyCallback = this.replyCallback.bind(this);
|
|
}
|
|
|
|
voteUp() {
|
|
this.voteService.voteCommentUp(this.comment.id).subscribe((result) => {
|
|
this.change && this.change()
|
|
});
|
|
}
|
|
|
|
voteDown() {
|
|
this.voteService.voteCommentDown(this.comment.id).subscribe((result) => {
|
|
this.change && this.change()
|
|
});
|
|
}
|
|
|
|
author(author : string) {
|
|
return '<a href="/u/' + author + '">' + author + '</a>';
|
|
}
|
|
|
|
replyCallback(): void {
|
|
this.comment.metadata.reply = false;
|
|
this.comment.metadata.comments = 0;
|
|
this.commentService.countParent(this.comment.target, this.comment.id).subscribe((data) => {
|
|
this.comment.metadata.comments = +data;
|
|
});
|
|
}
|
|
}
|