Skip to content

Commit 2b33d9e

Browse files
committed
Comments: Add thread line fix #33
1 parent a0758c4 commit 2b33d9e

File tree

6 files changed

+38
-15
lines changed

6 files changed

+38
-15
lines changed

Packages/Backend/Sources/Backend/Models/Comment.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public struct Comment: Decodable, Identifiable {
2020
public let isSubmitter: Bool?
2121
public let author: String?
2222
public let lindId: String?
23+
public let parentId: String?
2324
public let created: Date?
2425
public let createdUtc: Date?
2526
public let replies: Replies?
@@ -72,6 +73,7 @@ public let static_comment = Comment(id: UUID().uuidString,
7273
isSubmitter: false,
7374
author: "TestUser",
7475
lindId: "",
76+
parentId: "",
7577
created: Date(),
7678
createdUtc: Date(),
7779
replies: .none(""),

RedditOs/Features/Comments/CommentRow.swift

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,21 @@ struct CommentRow: View {
1717
viewModel.comment.name == "t1_id"
1818
}
1919

20-
init(comment: Comment) {
20+
let isRoot: Bool
21+
22+
init(comment: Comment, isRoot: Bool) {
23+
self.isRoot = isRoot
2124
_viewModel = StateObject(wrappedValue: CommentViewModel(comment: comment))
2225
}
2326

2427
var body: some View {
2528
HStack(alignment: .top) {
26-
CommentVoteView(viewModel: viewModel).padding(.top, 4)
29+
if !isRoot {
30+
Rectangle()
31+
.frame(width: 1)
32+
.background(Color.white)
33+
.padding(.bottom, 8)
34+
}
2735
VStack(alignment: .leading, spacing: 8) {
2836
HStack(spacing: 0) {
2937
HStack(spacing: 6) {
@@ -88,8 +96,11 @@ struct CommentRow: View {
8896
.font(.footnote)
8997
.foregroundColor(.gray)
9098
}
91-
CommentActionsView(viewModel: viewModel)
92-
.foregroundColor(.gray)
99+
HStack(spacing: 16) {
100+
CommentVoteView(viewModel: viewModel)
101+
CommentActionsView(viewModel: viewModel)
102+
.foregroundColor(.gray)
103+
}
93104
Divider()
94105
}.padding(.vertical, 4)
95106
}
@@ -99,10 +110,13 @@ struct CommentRow: View {
99110
struct CommentRow_Previews: PreviewProvider {
100111
static var previews: some View {
101112
List {
102-
CommentRow(comment: static_comment)
103-
CommentRow(comment: static_comment)
104-
CommentRow(comment: static_comment)
105-
CommentRow(comment: static_comment)
113+
CommentRow(comment: static_comment, isRoot: true)
114+
CommentRow(comment: static_comment, isRoot: false)
115+
CommentRow(comment: static_comment, isRoot: true)
116+
CommentRow(comment: static_comment, isRoot: false)
117+
CommentRow(comment: static_comment, isRoot: false)
118+
CommentRow(comment: static_comment, isRoot: false)
106119
}
120+
.frame(height: 800)
107121
}
108122
}

RedditOs/Features/Comments/CommentVoteView.swift

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,33 @@ struct CommentVoteView: View {
1212
@ObservedObject var viewModel: CommentViewModel
1313

1414
var body: some View {
15-
VStack(spacing: 6) {
15+
HStack(spacing: 6) {
1616
Button(action: {
1717
viewModel.postVote(vote: viewModel.comment.likes == true ? .neutral : .upvote)
1818
},
1919
label: {
2020
Image(systemName: "arrowtriangle.up.circle")
2121
.resizable()
22-
.frame(width: 16, height: 16)
22+
.frame(width: 12, height: 12)
2323
.foregroundColor(viewModel.comment.likes == true ? .accentColor : nil)
2424
}).buttonStyle(BorderlessButtonStyle())
2525

26+
Text(viewModel.comment.score?.toRoundedSuffixAsString() ?? "Vote")
27+
.font(.callout)
28+
.fontWeight(.bold)
29+
.minimumScaleFactor(0.1)
30+
.lineLimit(1)
31+
2632
Button(action: {
2733
viewModel.postVote(vote: viewModel.comment.likes == false ? .neutral : .downvote)
2834
},
2935
label: {
3036
Image(systemName: "arrowtriangle.down.circle")
3137
.resizable()
32-
.frame(width: 16, height: 16)
38+
.frame(width: 12, height: 12)
3339
.foregroundColor(viewModel.comment.likes == false ? .redditBlue : nil)
3440
}).buttonStyle(BorderlessButtonStyle())
35-
}.frame(width: 20)
41+
}
3642
}
3743
}
3844

RedditOs/Features/Post/PostDetailCommentsSection.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ struct PostDetailCommentsSection: View {
2727

2828
RecursiveView(data: viewModel.comments ?? placeholderComments,
2929
children: \.repliesComments) { comment in
30-
CommentRow(comment: comment)
30+
CommentRow(comment: comment,
31+
isRoot: comment.parentId == "t3_" + viewModel.post.id || viewModel.comments == nil)
3132
.redacted(reason: viewModel.comments == nil ? .placeholder : [])
3233
}
3334
}

RedditOs/Features/Profile/ProfileView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ struct ProfileView: View {
5858
case let .post(post):
5959
SubredditPostRow(post: post, displayMode: .constant(.large))
6060
case let .comment(comment):
61-
CommentRow(comment: comment)
61+
CommentRow(comment: comment, isRoot: true)
6262
default:
6363
Text("Unsupported view")
6464
}

RedditOs/Features/Users/sheet/UserSheetCommentsView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ struct UserSheetCommentsView: View {
1616
var body: some View {
1717
List {
1818
ForEach(viewModel.comments ?? loadingPlaceholders) { comment in
19-
CommentRow(comment: comment).redacted(reason: viewModel.comments != nil ? [] : .placeholder)
19+
CommentRow(comment: comment, isRoot: true).redacted(reason: viewModel.comments != nil ? [] : .placeholder)
2020
}
2121
if viewModel.comments != nil {
2222
LoadingRow(text: "Loading next page")

0 commit comments

Comments
 (0)