update comments

This commit is contained in:
2021-10-04 14:14:03 +02:00
parent 0cabe9b0a5
commit 1f427fd67e
11 changed files with 129 additions and 84 deletions
+2 -4
View File
@@ -5,10 +5,8 @@
<p class="text">{{entry.text}}</p>
<ui-commentform [target]="entry.id" [change]="boundReplyCallback"></ui-commentform>
<ui-commentform [target]="entry.id" (replyCommentEvent)="replyCallback($event)"></ui-commentform>
<ng-container *ngIf="entry.metadata.comments">
<ui-comments [target]="entry.id"></ui-comments>
</ng-container>
<ui-comments #comments [target]="entry.id"></ui-comments>
</ng-container>
</div>
+6 -9
View File
@@ -1,9 +1,10 @@
import { Component, OnInit } from '@angular/core';
import { Component, OnInit, ViewChild } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { EntriesService } from '../../services/entries.service';
import { CommentService } from '../../services/comment.service';
import { UiComments } from '../../ui/comments/comments.ui';
@Component({
selector: 'page-entry',
@@ -16,7 +17,7 @@ export class PageEntry implements OnInit {
entry: any;
notfound: boolean = false;
boundRefresh: Function;
boundReplyCallback: Function;
@ViewChild('comments') comments: UiComments;
constructor(private commentService: CommentService, private entriesService: EntriesService,
private route: ActivatedRoute) { }
@@ -24,7 +25,6 @@ export class PageEntry implements OnInit {
ngOnInit(): void {
this.id = +this.route.snapshot.paramMap.get('id');
this.boundRefresh = this.refresh.bind(this);
this.boundReplyCallback = this.replyCallback.bind(this);
this.refresh();
}
@@ -38,12 +38,9 @@ export class PageEntry implements OnInit {
})
}
replyCallback(): void {
this.entry.metadata.reply = false;
this.entry.metadata.comments = 0;
this.commentService.count(this.entry.id).subscribe((data) => {
this.entry.metadata.comments = +data;
});
replyCallback(comment): void {
this.comments.addComment(comment);
this.entry.metadata.comments = (this.entry.metadata.comments || 0) + 1;
}
}