From 2b33d9e742ab342add30f553e877905339ee40f1 Mon Sep 17 00:00:00 2001 From: Thomas Ricouard Date: Wed, 19 May 2021 21:05:12 +0200 Subject: [PATCH] Comments: Add thread line fix #33 --- .../Sources/Backend/Models/Comment.swift | 2 ++ RedditOs/Features/Comments/CommentRow.swift | 30 ++++++++++++++----- .../Features/Comments/CommentVoteView.swift | 14 ++++++--- .../Post/PostDetailCommentsSection.swift | 3 +- RedditOs/Features/Profile/ProfileView.swift | 2 +- .../Users/sheet/UserSheetCommentsView.swift | 2 +- 6 files changed, 38 insertions(+), 15 deletions(-) diff --git a/Packages/Backend/Sources/Backend/Models/Comment.swift b/Packages/Backend/Sources/Backend/Models/Comment.swift index 99efb3f..0e13a57 100644 --- a/Packages/Backend/Sources/Backend/Models/Comment.swift +++ b/Packages/Backend/Sources/Backend/Models/Comment.swift @@ -20,6 +20,7 @@ public struct Comment: Decodable, Identifiable { public let isSubmitter: Bool? public let author: String? public let lindId: String? + public let parentId: String? public let created: Date? public let createdUtc: Date? public let replies: Replies? @@ -72,6 +73,7 @@ public let static_comment = Comment(id: UUID().uuidString, isSubmitter: false, author: "TestUser", lindId: "", + parentId: "", created: Date(), createdUtc: Date(), replies: .none(""), diff --git a/RedditOs/Features/Comments/CommentRow.swift b/RedditOs/Features/Comments/CommentRow.swift index f6e7560..94a0f5c 100644 --- a/RedditOs/Features/Comments/CommentRow.swift +++ b/RedditOs/Features/Comments/CommentRow.swift @@ -17,13 +17,21 @@ struct CommentRow: View { viewModel.comment.name == "t1_id" } - init(comment: Comment) { + let isRoot: Bool + + init(comment: Comment, isRoot: Bool) { + self.isRoot = isRoot _viewModel = StateObject(wrappedValue: CommentViewModel(comment: comment)) } var body: some View { HStack(alignment: .top) { - CommentVoteView(viewModel: viewModel).padding(.top, 4) + if !isRoot { + Rectangle() + .frame(width: 1) + .background(Color.white) + .padding(.bottom, 8) + } VStack(alignment: .leading, spacing: 8) { HStack(spacing: 0) { HStack(spacing: 6) { @@ -88,8 +96,11 @@ struct CommentRow: View { .font(.footnote) .foregroundColor(.gray) } - CommentActionsView(viewModel: viewModel) - .foregroundColor(.gray) + HStack(spacing: 16) { + CommentVoteView(viewModel: viewModel) + CommentActionsView(viewModel: viewModel) + .foregroundColor(.gray) + } Divider() }.padding(.vertical, 4) } @@ -99,10 +110,13 @@ struct CommentRow: View { struct CommentRow_Previews: PreviewProvider { static var previews: some View { List { - CommentRow(comment: static_comment) - CommentRow(comment: static_comment) - CommentRow(comment: static_comment) - CommentRow(comment: static_comment) + CommentRow(comment: static_comment, isRoot: true) + CommentRow(comment: static_comment, isRoot: false) + CommentRow(comment: static_comment, isRoot: true) + CommentRow(comment: static_comment, isRoot: false) + CommentRow(comment: static_comment, isRoot: false) + CommentRow(comment: static_comment, isRoot: false) } + .frame(height: 800) } } diff --git a/RedditOs/Features/Comments/CommentVoteView.swift b/RedditOs/Features/Comments/CommentVoteView.swift index 847f958..51aea28 100644 --- a/RedditOs/Features/Comments/CommentVoteView.swift +++ b/RedditOs/Features/Comments/CommentVoteView.swift @@ -12,27 +12,33 @@ struct CommentVoteView: View { @ObservedObject var viewModel: CommentViewModel var body: some View { - VStack(spacing: 6) { + HStack(spacing: 6) { Button(action: { viewModel.postVote(vote: viewModel.comment.likes == true ? .neutral : .upvote) }, label: { Image(systemName: "arrowtriangle.up.circle") .resizable() - .frame(width: 16, height: 16) + .frame(width: 12, height: 12) .foregroundColor(viewModel.comment.likes == true ? .accentColor : nil) }).buttonStyle(BorderlessButtonStyle()) + Text(viewModel.comment.score?.toRoundedSuffixAsString() ?? "Vote") + .font(.callout) + .fontWeight(.bold) + .minimumScaleFactor(0.1) + .lineLimit(1) + Button(action: { viewModel.postVote(vote: viewModel.comment.likes == false ? .neutral : .downvote) }, label: { Image(systemName: "arrowtriangle.down.circle") .resizable() - .frame(width: 16, height: 16) + .frame(width: 12, height: 12) .foregroundColor(viewModel.comment.likes == false ? .redditBlue : nil) }).buttonStyle(BorderlessButtonStyle()) - }.frame(width: 20) + } } } diff --git a/RedditOs/Features/Post/PostDetailCommentsSection.swift b/RedditOs/Features/Post/PostDetailCommentsSection.swift index dd55fa0..7ef22fb 100644 --- a/RedditOs/Features/Post/PostDetailCommentsSection.swift +++ b/RedditOs/Features/Post/PostDetailCommentsSection.swift @@ -27,7 +27,8 @@ struct PostDetailCommentsSection: View { RecursiveView(data: viewModel.comments ?? placeholderComments, children: \.repliesComments) { comment in - CommentRow(comment: comment) + CommentRow(comment: comment, + isRoot: comment.parentId == "t3_" + viewModel.post.id || viewModel.comments == nil) .redacted(reason: viewModel.comments == nil ? .placeholder : []) } } diff --git a/RedditOs/Features/Profile/ProfileView.swift b/RedditOs/Features/Profile/ProfileView.swift index 927d951..32402a0 100644 --- a/RedditOs/Features/Profile/ProfileView.swift +++ b/RedditOs/Features/Profile/ProfileView.swift @@ -58,7 +58,7 @@ struct ProfileView: View { case let .post(post): SubredditPostRow(post: post, displayMode: .constant(.large)) case let .comment(comment): - CommentRow(comment: comment) + CommentRow(comment: comment, isRoot: true) default: Text("Unsupported view") } diff --git a/RedditOs/Features/Users/sheet/UserSheetCommentsView.swift b/RedditOs/Features/Users/sheet/UserSheetCommentsView.swift index a6c92d3..90c0a7f 100644 --- a/RedditOs/Features/Users/sheet/UserSheetCommentsView.swift +++ b/RedditOs/Features/Users/sheet/UserSheetCommentsView.swift @@ -16,7 +16,7 @@ struct UserSheetCommentsView: View { var body: some View { List { ForEach(viewModel.comments ?? loadingPlaceholders) { comment in - CommentRow(comment: comment).redacted(reason: viewModel.comments != nil ? [] : .placeholder) + CommentRow(comment: comment, isRoot: true).redacted(reason: viewModel.comments != nil ? [] : .placeholder) } if viewModel.comments != nil { LoadingRow(text: "Loading next page")