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 d9bc3652509ab282964defb1505e6bee4d8c0808..f26675e9c1bac05a004c5b8673b5111f24532c8c 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)="filterMarkAsCorrect()"> + <button mat-icon-button (focus)="hideCommentsList=true" (click)="filter(correct)"> <mat-icon>check_circle</mat-icon> </button> - <button mat-icon-button (focus)="hideCommentsList=true" (click)="filterFavorite()"> + <button mat-icon-button (focus)="hideCommentsList=true" (click)="filter(favorite)"> <mat-icon>favorite</mat-icon> </button> - <button mat-icon-button (focus)="hideCommentsList=true" (click)="filterMarkAsRead()"> + <button mat-icon-button (focus)="hideCommentsList=true" (click)="filter(read)"> <mat-icon>visibility</mat-icon> </button> - <button mat-icon-button (focus)="hideCommentsList=true" (click)="filterMarkAsUnread()"> + <button mat-icon-button (focus)="hideCommentsList=true" (click)="filter(unread)"> <mat-icon>visibility_off</mat-icon> </button> 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 689465f6db248c8fc0448c2d4e0d6477eebc3526..f01c51b11ac33cfeeb50073fc2347ea4b7183a4b 100644 --- a/src/app/components/shared/comment-list/comment-list.component.ts +++ b/src/app/components/shared/comment-list/comment-list.component.ts @@ -33,6 +33,11 @@ export class CommentListComponent implements OnInit { timeasc = 'time_asc'; timedesc = 'time_desc'; currentSort = this.votedesc; + read = 'read'; + unread = 'unread'; + favorite = 'favorite'; + correct = 'correct'; + currentFilter = ''; constructor(private commentService: CommentService, private translateService: TranslateService, @@ -105,13 +110,13 @@ export class CommentListComponent implements OnInit { if (payload.id === this.comments[i].id) { for (const [key, value] of Object.entries(payload.changes)) { switch (key) { - case 'read': + case this.read: this.comments[i].read = <boolean>value; break; - case 'correct': + case this.correct: this.comments[i].correct = <boolean>value; break; - case 'favorite': + case this.favorite: this.comments[i].favorite = <boolean>value; break; case 'score': @@ -138,6 +143,7 @@ export class CommentListComponent implements OnInit { } break; } + this.filter(this.currentFilter); } openCreateDialog(): void { @@ -164,25 +170,42 @@ export class CommentListComponent implements OnInit { this.filteredComments = this.comments.filter(c => c.favorite); } - filterMarkAsRead(): void { + filterRead(): void { this.filteredComments = this.comments.filter(c => c.read); } - filterMarkAsUnread(): void { + filterUnread(): void { this.filteredComments = this.comments.filter(c => !c.read); } - filterMarkAsCorrect(): void { + filterCorrect(): void { this.filteredComments = this.comments.filter(c => c.correct); } + filter(type: string): void { + this.currentFilter = type; + switch (type) { + case this.correct: + this.filterCorrect(); + break; + case this.favorite: + this.filterFavorite(); + break; + case this.read: + this.filterRead(); + break; + case this.unread: + this.filterUnread(); + } + } + sort(type: string): void { this.currentSort = type; if (type === this.voteasc) { this.sortVote(); } else if (type === this.votedesc) { this.sortVoteDesc(); - } else if (this.timeasc || this.timedesc) { + } else { this.sortTime(type); } }