bstlboard-front/src/app/pages/entry/entry.page.ts

51 lines
1.3 KiB
TypeScript

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',
templateUrl: './entry.page.html',
styleUrls: ['./entry.page.scss']
})
export class PageEntry implements OnInit {
id: number;
entry: any;
notfound: boolean = false;
boundRefresh: Function;
@ViewChild('comments') comments: UiComments;
constructor(private commentService: CommentService, private entriesService: EntriesService,
private route: ActivatedRoute) { }
ngOnInit(): void {
this.id = +this.route.snapshot.paramMap.get('id');
this.boundRefresh = this.refresh.bind(this);
this.refresh();
}
refresh() {
this.entriesService.getEntry(this.id).subscribe({
next: (data) => {
this.entry = data;
},
error: (error) => {
if (error.status == 404) {
this.entry = false;
this.notfound = true;
}
}
})
}
replyCallback(comment): void {
this.comments.addComment(comment);
this.entry.metadata.comments = (this.entry.metadata.comments || 0) + 1;
}
}