From 096a2ede1561a69175b27ebade05767ca0b3d857 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20Mau=C3=9F?= <lukas.mauss@mni.thm.de> Date: Sat, 8 Jun 2019 17:00:16 +0200 Subject: [PATCH] Stop filter and sort comments permanently --- .../comment-list/comment-list.component.html | 10 +++++----- .../comment-list/comment-list.component.ts | 19 +++++++------------ 2 files changed, 12 insertions(+), 17 deletions(-) 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 4d6ad8fc3..f90ad45ee 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 5d30aff49..5c2015db9 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: -- GitLab