56 lines
1.7 KiB
TypeScript
56 lines
1.7 KiB
TypeScript
import { Component, OnInit, OnDestroy } from '@angular/core';
|
|
|
|
import { Router, ActivatedRoute } from '@angular/router';
|
|
import { Subscription } from 'rxjs';
|
|
|
|
import { CommentService } from '../../../services/comment.service';
|
|
import { SettingsService } from '../../../services/settings.service';
|
|
|
|
@Component({
|
|
selector: 'page-usercomments',
|
|
templateUrl: './usercomments.page.html',
|
|
styleUrls: ['./usercomments.page.scss']
|
|
})
|
|
export class PageUserComments implements OnInit, OnDestroy {
|
|
|
|
settings: any;
|
|
username: string;
|
|
comments: any = {};
|
|
init: boolean = true;
|
|
ignore: string[] = ["author"];
|
|
settingsSubscription: Subscription;
|
|
|
|
constructor(private settingsService: SettingsService, private commentService: CommentService, private router: Router, private route: ActivatedRoute) { }
|
|
|
|
ngOnInit(): void {
|
|
this.username = this.route.snapshot.paramMap.get('username');
|
|
this.settingsSubscription = this.settingsService.settings.subscribe({
|
|
next: (settings) => {
|
|
this.settings = settings;
|
|
this.commentService.getByUser(this.username, this.comments.number || 0, this.comments.size || this.settings.pageSize, this.ignore).subscribe({
|
|
next: (data: any) => {
|
|
this.comments = data;
|
|
}
|
|
})
|
|
}
|
|
})
|
|
}
|
|
|
|
ngOnDestroy(): void {
|
|
this.settingsSubscription.unsubscribe();
|
|
}
|
|
|
|
showMore() {
|
|
const oldContent: any[] = this.comments.content;
|
|
this.commentService.getByUser(this.username, this.comments.number + 1, this.comments.size, this.ignore).subscribe({
|
|
next: (data) => {
|
|
this.comments = data;
|
|
for (let comment of this.comments.content) {
|
|
oldContent.push(comment);
|
|
}
|
|
this.comments.content = oldContent;
|
|
}
|
|
})
|
|
}
|
|
}
|