Skip to content

Commit ceb496c

Browse files
committed
When post author = comment author, set color
Change the comment author color to the accentColor if the comment author is the same as the post author.
1 parent 45f44e5 commit ceb496c

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

Shared/Views/CommentsView.swift

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ struct CommentsView: View {
2727
// `dropFirst` because `first` is the actual post
2828
if listings!.dropFirst().map({ $0.data.children }).flatMap({ $0.map { $0.data } }).count > 0 {
2929
ForEach(listings!.dropFirst().map({ $0.data.children }).flatMap { $0.map { $0.data } }, id: \.id) { comment in
30-
CommentView(comment: comment, nestLevel: 0)
30+
CommentView(comment: comment, postAuthor: self.post.author, nestLevel: 0)
3131
}
3232
} else {
3333
self.noComments
@@ -42,6 +42,7 @@ struct CommentsView: View {
4242

4343
struct CommentView: View {
4444
let comment: Comment
45+
let postAuthor: String
4546
let nestLevel: Int
4647

4748
var body: some View {
@@ -56,12 +57,17 @@ struct CommentView: View {
5657
/// Content
5758
VStack(alignment: .leading) {
5859
HStack {
59-
Text(comment.author)
60+
if comment.author == postAuthor {
61+
Text(comment.author)
62+
.foregroundColor(.accentColor)
63+
} else {
64+
Text(comment.author)
65+
}
6066
Image(systemName: "arrow.up")
6167
Text("\(comment.score)")
6268
}
63-
.font(.caption)
64-
.opacity(0.75)
69+
.font(.caption)
70+
.opacity(0.75)
6571
Text(comment.body ?? "")
6672
}
6773
}
@@ -70,7 +76,7 @@ struct CommentView: View {
7076
/// Recursive comments
7177
if comment.replies != nil {
7278
ForEach(comment.replies!.data.children.map { $0.data }, id: \.id) { reply in
73-
CommentView(comment: reply, nestLevel: self.nestLevel + 1)
79+
CommentView(comment: reply, postAuthor: self.postAuthor, nestLevel: self.nestLevel + 1)
7480
}
7581
}
7682
}

0 commit comments

Comments
 (0)