2021-12-05 01:05:41 +05:30
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
struct CommentsView: View {
|
|
|
|
@State private var repliesID: Comment.ID?
|
|
|
|
|
2022-11-25 02:06:05 +05:30
|
|
|
@ObservedObject private var comments = CommentsModel.shared
|
2021-12-05 01:05:41 +05:30
|
|
|
|
|
|
|
var body: some View {
|
2021-12-05 22:44:49 +05:30
|
|
|
Group {
|
|
|
|
if comments.disabled {
|
2022-09-28 21:15:05 +05:30
|
|
|
NoCommentsView(text: "Comments are disabled".localized(), systemImage: "xmark.circle.fill")
|
2021-12-05 22:44:49 +05:30
|
|
|
} else if comments.loaded && comments.all.isEmpty {
|
2022-09-28 21:15:05 +05:30
|
|
|
NoCommentsView(text: "No comments".localized(), systemImage: "0.circle.fill")
|
2021-12-05 22:44:49 +05:30
|
|
|
} else if !comments.loaded {
|
2021-12-30 00:09:38 +05:30
|
|
|
PlaceholderProgressView()
|
2021-12-05 22:44:49 +05:30
|
|
|
} else {
|
2022-01-05 21:42:32 +05:30
|
|
|
let last = comments.all.last
|
2023-05-08 01:15:07 +05:30
|
|
|
LazyVStack {
|
2022-01-05 21:42:32 +05:30
|
|
|
ForEach(comments.all) { comment in
|
|
|
|
CommentView(comment: comment, repliesID: $repliesID)
|
|
|
|
.onAppear {
|
|
|
|
comments.loadNextPageIfNeeded(current: comment)
|
2021-12-05 22:44:49 +05:30
|
|
|
}
|
2022-06-25 05:09:29 +05:30
|
|
|
.borderBottom(height: comment != last ? 0.5 : 0, color: Color("ControlsBorderColor"))
|
2021-12-05 01:05:41 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
.padding(.horizontal)
|
2021-12-05 22:44:49 +05:30
|
|
|
}
|
2021-12-05 01:05:41 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
struct CommentsView_Previews: PreviewProvider {
|
|
|
|
static var previews: some View {
|
2023-10-15 17:05:23 +05:30
|
|
|
if #available(iOS 15.0, macOS 12.0, tvOS 15.0, *) {
|
|
|
|
CommentsView()
|
|
|
|
.previewInterfaceOrientation(.landscapeRight)
|
|
|
|
.injectFixtureEnvironmentObjects()
|
|
|
|
}
|
|
|
|
|
2021-12-05 01:05:41 +05:30
|
|
|
CommentsView()
|
|
|
|
.injectFixtureEnvironmentObjects()
|
|
|
|
}
|
|
|
|
}
|