From ceb496cfd3facc343d22d5460da942c01f0422c5 Mon Sep 17 00:00:00 2001 From: Andrew Robinson Date: Sat, 19 Oct 2019 14:01:26 -0700 Subject: [PATCH 1/3] 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. --- Shared/Views/CommentsView.swift | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/Shared/Views/CommentsView.swift b/Shared/Views/CommentsView.swift index 774814a..8ce5820 100644 --- a/Shared/Views/CommentsView.swift +++ b/Shared/Views/CommentsView.swift @@ -27,7 +27,7 @@ struct CommentsView: View { // `dropFirst` because `first` is the actual post if listings!.dropFirst().map({ $0.data.children }).flatMap({ $0.map { $0.data } }).count > 0 { ForEach(listings!.dropFirst().map({ $0.data.children }).flatMap { $0.map { $0.data } }, id: \.id) { comment in - CommentView(comment: comment, nestLevel: 0) + CommentView(comment: comment, postAuthor: self.post.author, nestLevel: 0) } } else { self.noComments @@ -42,6 +42,7 @@ struct CommentsView: View { struct CommentView: View { let comment: Comment + let postAuthor: String let nestLevel: Int var body: some View { @@ -56,12 +57,17 @@ struct CommentView: View { /// Content VStack(alignment: .leading) { HStack { - Text(comment.author) + if comment.author == postAuthor { + Text(comment.author) + .foregroundColor(.accentColor) + } else { + Text(comment.author) + } Image(systemName: "arrow.up") Text("\(comment.score)") } - .font(.caption) - .opacity(0.75) + .font(.caption) + .opacity(0.75) Text(comment.body ?? "") } } @@ -70,7 +76,7 @@ struct CommentView: View { /// Recursive comments if comment.replies != nil { ForEach(comment.replies!.data.children.map { $0.data }, id: \.id) { reply in - CommentView(comment: reply, nestLevel: self.nestLevel + 1) + CommentView(comment: reply, postAuthor: self.postAuthor, nestLevel: self.nestLevel + 1) } } } From 1a6be7b652836bb9e0c305dc989ebb520ad682b8 Mon Sep 17 00:00:00 2001 From: Andrew Robinson Date: Sat, 19 Oct 2019 14:11:26 -0700 Subject: [PATCH 2/3] Move the authorText view in to a variables --- Shared/Views/CommentsView.swift | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/Shared/Views/CommentsView.swift b/Shared/Views/CommentsView.swift index 8ce5820..7357184 100644 --- a/Shared/Views/CommentsView.swift +++ b/Shared/Views/CommentsView.swift @@ -44,6 +44,14 @@ struct CommentView: View { let comment: Comment let postAuthor: String let nestLevel: Int + + var authorText: some View { + if comment.author == postAuthor { + return Text(comment.author).foregroundColor(.accentColor) + } else { + return Text(comment.author) + } + } var body: some View { Group { @@ -57,12 +65,7 @@ struct CommentView: View { /// Content VStack(alignment: .leading) { HStack { - if comment.author == postAuthor { - Text(comment.author) - .foregroundColor(.accentColor) - } else { - Text(comment.author) - } + authorText Image(systemName: "arrow.up") Text("\(comment.score)") } From 4f01a1fc317450a4980a4ec825338cfd0b59a264 Mon Sep 17 00:00:00 2001 From: Andrew Robinson Date: Sat, 19 Oct 2019 14:39:29 -0700 Subject: [PATCH 3/3] Bold the text when the post author equals comment author --- Shared/Views/CommentsView.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Shared/Views/CommentsView.swift b/Shared/Views/CommentsView.swift index 7357184..8bde9c2 100644 --- a/Shared/Views/CommentsView.swift +++ b/Shared/Views/CommentsView.swift @@ -47,7 +47,7 @@ struct CommentView: View { var authorText: some View { if comment.author == postAuthor { - return Text(comment.author).foregroundColor(.accentColor) + return Text(comment.author).foregroundColor(.accentColor).bold() } else { return Text(comment.author) }