diff --git a/src/app/components/shared/comment-list/comment-list.component.html b/src/app/components/shared/comment-list/comment-list.component.html index 4d6ad8fc36bb05ea6063081bdf32b6bb882dd922..f90ad45eedcc350340cf32d956d47a3b27034d3a 100644 --- a/src/app/components/shared/comment-list/comment-list.component.html +++ b/src/app/components/shared/comment-list/comment-list.component.html @@ -44,19 +44,19 @@ <mat-menu #filterMenu="matMenu" xPosition="before"> <div> - <button mat-icon-button (focus)="hideCommentsList=true" (click)="filter(correct)"> + <button mat-icon-button (focus)="hideCommentsList=true" (click)="filterComments(correct)"> <mat-icon [ngClass]="{correct: 'correct-icon'}[currentFilter]">check_circle</mat-icon> </button> - <button mat-icon-button (focus)="hideCommentsList=true" (click)="filter(favorite)"> + <button mat-icon-button (focus)="hideCommentsList=true" (click)="filterComments(favorite)"> <mat-icon [ngClass]="{favorite: 'favorite-icon'}[currentFilter]">favorite</mat-icon> </button> - <button mat-icon-button (focus)="hideCommentsList=true" (click)="filter(read)"> + <button mat-icon-button (focus)="hideCommentsList=true" (click)="filterComments(read)"> <mat-icon [ngClass]="{read: 'read-icon'}[currentFilter]">visibility</mat-icon> </button> - <button mat-icon-button (focus)="hideCommentsList=true" (click)="filter(unread)"> + <button mat-icon-button (focus)="hideCommentsList=true" (click)="filterComments(unread)"> <mat-icon [ngClass]="{unread: 'unread-icon'}[currentFilter]">visibility_off</mat-icon> </button> @@ -67,7 +67,7 @@ </mat-menu> </div> -<app-comment *ngFor="let current of showComments()" [comment]="current" [parseVote]="getVote(current)"></app-comment> +<app-comment *ngFor="let current of hideCommentsList ? filteredComments : comments" [comment]="current" [parseVote]="getVote(current)"></app-comment> <div *ngIf="comments.length < 1" fxLayout="row" fxLayoutAlign="center center" class="no-comments"> <h4>{{ 'comment-page.no-comments' | translate }}</h4> diff --git a/src/app/components/shared/comment-list/comment-list.component.ts b/src/app/components/shared/comment-list/comment-list.component.ts index 5d30aff4983393e5eabfa42b5fdef80a87777b95..5c2015db9409c53e645c47976eaea3105cb62faa 100644 --- a/src/app/components/shared/comment-list/comment-list.component.ts +++ b/src/app/components/shared/comment-list/comment-list.component.ts @@ -70,6 +70,7 @@ export class CommentListComponent implements OnInit { this.translateService.use(localStorage.getItem('currentLang')); this.userRole = this.authenticationService.getRole(); this.deviceType = localStorage.getItem('deviceType'); + this.getComments(); } searchComments(term: string): void { @@ -81,23 +82,16 @@ export class CommentListComponent implements OnInit { } } - showComments(): Comment[] { + getComments(): void { this.isLoading = false; let commentThreshold = -10; if (this.room.extensions && this.room.extensions['comments']) { commentThreshold = this.room.extensions['comments'].commentThreshold; if (this.hideCommentsList) { - return this.filteredComments.filter( x => x.score >= commentThreshold ); + this.filteredComments = this.filteredComments.filter( x => x.score >= commentThreshold ); } else { this.sort(this.currentSort); - return this.comments.filter( x => x.score >= commentThreshold ); - } - } else { - if (this.hideCommentsList) { - return this.filteredComments; - } else { - this.sort(this.currentSort); - return this.comments; + this.comments = this.comments.filter( x => x.score >= commentThreshold ); } } } @@ -157,7 +151,8 @@ export class CommentListComponent implements OnInit { } break; } - this.filter(this.currentFilter); + this.filterComments(this.currentFilter); + this.sort(this.currentSort); } openCreateDialog(): void { @@ -196,7 +191,7 @@ export class CommentListComponent implements OnInit { this.filteredComments = this.comments.filter(c => c.correct); } - filter(type: string): void { + filterComments(type: string): void { this.currentFilter = type; switch (type) { case this.correct: