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 6ba72d10bab4702a7b12fbc9fa786c5c5462bb8f..ec2c3b39112c2dacf243d4b1ca33d491697f065a 100644 --- a/src/app/components/shared/comment-list/comment-list.component.html +++ b/src/app/components/shared/comment-list/comment-list.component.html @@ -32,17 +32,17 @@ </div> <mat-menu #sortMenu="matMenu" xPosition="before"> - <button mat-icon-button (focus)="hideCommentsList=false" matTooltip="{{ 'comment-list.vote-desc' | translate }}" + <button mat-icon-button matTooltip="{{ 'comment-list.vote-desc' | translate }}" (click)="sortComments(votedesc)"> <mat-icon [ngClass]="{votedesc: 'up'}[currentSort]">keyboard_arrow_up</mat-icon> </button> - <button mat-icon-button (focus)="hideCommentsList=false" matTooltip="{{ 'comment-list.vote-asc' | translate }}" + <button mat-icon-button matTooltip="{{ 'comment-list.vote-asc' | translate }}" (click)="sortComments(voteasc)"> <mat-icon [ngClass]="{voteasc: 'down'}[currentSort]">keyboard_arrow_down</mat-icon> </button> - <button mat-icon-button (focus)="hideCommentsList=false" matTooltip="{{ 'comment-list.time' | translate }}" + <button mat-icon-button matTooltip="{{ 'comment-list.time' | translate }}" (click)="sortComments(time)"> <mat-icon [ngClass]="{time: 'unread-icon'}[currentSort]">access_time</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 75409636d6b500c41cbbaaaccd9aadda67da4100..07d8d80547f74e764f75374b73f5fe6798eae502 100644 --- a/src/app/components/shared/comment-list/comment-list.component.ts +++ b/src/app/components/shared/comment-list/comment-list.component.ts @@ -95,8 +95,6 @@ export class CommentListComponent implements OnInit { if (this.searchInput && this.searchInput.length > 2) { this.hideCommentsList = true; this.filteredComments = this.comments.filter(c => c.body.toLowerCase().includes(this.searchInput.toLowerCase())); - } else { - this.hideCommentsList = false; } } @@ -171,8 +169,8 @@ export class CommentListComponent implements OnInit { } break; } - this.sortComments(this.currentSort); this.filterComments(this.currentFilter); + this.sortComments(this.currentSort); this.searchComments(); } @@ -214,10 +212,11 @@ export class CommentListComponent implements OnInit { return !c.read; } }); + this.sortComments(this.currentSort); } - sortComments(type: string): void { - this.comments.sort((a, b) => { + sort(array: any[], type: string): void { + array.sort((a, b) => { if (type === this.voteasc) { return a.score - b.score; } else if (type === this.votedesc) { @@ -228,6 +227,14 @@ export class CommentListComponent implements OnInit { return +dateB - +dateA; } }); + } + + sortComments(type: string): void { + if (this.hideCommentsList === true) { + this.sort(this.filteredComments, type); + } else { + this.sort(this.comments, type); + } this.currentSort = type; } } diff --git a/src/app/components/shared/comment/comment.component.scss b/src/app/components/shared/comment/comment.component.scss index d927f8b8c07e3c8b4c27ad506cff014a777ea926..fa3cfd026c35b256279d80e41848439e83e4ddbf 100644 --- a/src/app/components/shared/comment/comment.component.scss +++ b/src/app/components/shared/comment/comment.component.scss @@ -2,7 +2,7 @@ margin-bottom: 3%; background-color: var(--surface); padding: 1.5% 1.5% 3% 3%; - transition: background-color 1s linear; + transition: background-color 0.5s linear; } mat-card-content > :first-child { diff --git a/src/app/components/shared/comment/comment.component.ts b/src/app/components/shared/comment/comment.component.ts index 1fa3e0d5d93817cb97fbf88ed7fd4801fc0a99f0..1404cd4433ad3e2089c9bb6d4ca8032d2914e544 100644 --- a/src/app/components/shared/comment/comment.component.ts +++ b/src/app/components/shared/comment/comment.component.ts @@ -143,7 +143,9 @@ export class CommentComponent implements OnInit { this.goToFullScreen(document.documentElement); if (this.isStudent === false) { this.wsCommentService.highlight(comment); - this.setRead(comment); + if (!comment.read) { + this.setRead(comment); + } } const dialogRef = this.dialog.open(PresentCommentComponent, { position: {