Skip to content

Commit ca07088

Browse files
committed
fix(comments): make replies collapsed by default
1 parent 3a67400 commit ca07088

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<ion-list inset no-lines class="comments-list">
2-
<ion-item *ngFor="let comment of comments">
2+
<ion-item *ngFor="let comment of comments; trackBy: trackByCommentId">
33
<p class="comment-head">
44
<span class="comment-author">{{comment.author}}</span>
55
<span class="comment-score">{{comment.score}} points</span>
@@ -9,12 +9,12 @@
99
<button
1010
*ngIf="comment.replies.length"
1111
ion-button clear
12-
(click)="collapse(comment)"
12+
(click)="toggleExpanded(comment)"
1313
class="replies-toggle">
1414
<span>replies ({{comment.replies.length}})</span>
15-
<ion-icon name="ios-arrow-down" *ngIf="!comment.collapsed"></ion-icon>
16-
<ion-icon name="ios-arrow-forward" *ngIf="comment.collapsed"></ion-icon>
15+
<ion-icon name="ios-arrow-down" *ngIf="comment.expanded"></ion-icon>
16+
<ion-icon name="ios-arrow-forward" *ngIf="!comment.expanded"></ion-icon>
1717
</button>
18-
<comments-list *ngIf="comment.replies.length && !comment.collapsed" [comments]="comment.replies"></comments-list>
18+
<comments-list *ngIf="comment.replies.length && comment.expanded" [comments]="comment.replies"></comments-list>
1919
</ion-item>
2020
</ion-list>

src/pages/comments/commentsList/commentsList.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ export class CommentsList {
1010

1111
constructor() {}
1212

13-
collapse(comment) {
14-
comment.collapsed = !comment.collapsed;
13+
toggleExpanded(comment) {
14+
comment.expanded = !comment.expanded;
15+
}
16+
17+
trackByCommentId(index, comment) {
18+
return comment.id;
1519
}
1620
}

0 commit comments

Comments
 (0)