Skip to content

Commit

Permalink
Comments: Add thread line fix #33
Browse files Browse the repository at this point in the history
  • Loading branch information
Dimillian committed May 19, 2021
1 parent a0758c4 commit 2b33d9e
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 15 deletions.
2 changes: 2 additions & 0 deletions Packages/Backend/Sources/Backend/Models/Comment.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down Expand Up @@ -72,6 +73,7 @@ public let static_comment = Comment(id: UUID().uuidString,
isSubmitter: false,
author: "TestUser",
lindId: "",
parentId: "",
created: Date(),
createdUtc: Date(),
replies: .none(""),
Expand Down
30 changes: 22 additions & 8 deletions RedditOs/Features/Comments/CommentRow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
}
Expand All @@ -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)
}
}
14 changes: 10 additions & 4 deletions RedditOs/Features/Comments/CommentVoteView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}

Expand Down
3 changes: 2 additions & 1 deletion RedditOs/Features/Post/PostDetailCommentsSection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 : [])
}
}
Expand Down
2 changes: 1 addition & 1 deletion RedditOs/Features/Profile/ProfileView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down
2 changes: 1 addition & 1 deletion RedditOs/Features/Users/sheet/UserSheetCommentsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 2b33d9e

Please sign in to comment.