2021-12-04 19:35:41 +00:00
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
struct CommentsView: View {
|
|
|
|
@State private var repliesID: Comment.ID?
|
2024-08-19 22:52:04 +00:00
|
|
|
@State private var availableWidth = 0.0
|
2021-12-04 19:35:41 +00:00
|
|
|
|
2022-11-24 20:36:05 +00:00
|
|
|
@ObservedObject private var comments = CommentsModel.shared
|
2021-12-04 19:35:41 +00:00
|
|
|
|
|
|
|
var body: some View {
|
2021-12-05 17:14:49 +00:00
|
|
|
Group {
|
|
|
|
if comments.disabled {
|
2022-09-28 15:45:05 +00:00
|
|
|
NoCommentsView(text: "Comments are disabled".localized(), systemImage: "xmark.circle.fill")
|
2021-12-05 17:14:49 +00:00
|
|
|
} else if comments.loaded && comments.all.isEmpty {
|
2022-09-28 15:45:05 +00:00
|
|
|
NoCommentsView(text: "No comments".localized(), systemImage: "0.circle.fill")
|
2021-12-05 17:14:49 +00:00
|
|
|
} else if !comments.loaded {
|
2021-12-29 18:39:38 +00:00
|
|
|
PlaceholderProgressView()
|
2021-12-05 17:14:49 +00:00
|
|
|
} else {
|
2023-05-07 19:45:07 +00:00
|
|
|
LazyVStack {
|
2022-01-05 16:12:32 +00:00
|
|
|
ForEach(comments.all) { comment in
|
2024-08-19 22:52:04 +00:00
|
|
|
CommentView(comment: comment, repliesID: $repliesID, availableWidth: availableWidth)
|
2022-01-05 16:12:32 +00:00
|
|
|
.onAppear {
|
|
|
|
comments.loadNextPageIfNeeded(current: comment)
|
2021-12-05 17:14:49 +00:00
|
|
|
}
|
2024-08-19 22:52:04 +00:00
|
|
|
.borderBottom(height: comment != comments.all.last ? 0.5 : 0, color: Color("ControlsBorderColor"))
|
2021-12-04 19:35:41 +00:00
|
|
|
}
|
|
|
|
}
|
2024-08-19 22:52:04 +00:00
|
|
|
.background(GeometryReader { geometry in
|
|
|
|
Color.clear
|
|
|
|
.onAppear {
|
|
|
|
self.availableWidth = Double(geometry.size.width)
|
|
|
|
}
|
|
|
|
})
|
2021-12-04 19:35:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
.padding(.horizontal)
|
2021-12-05 17:14:49 +00:00
|
|
|
}
|
2021-12-04 19:35:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct CommentsView_Previews: PreviewProvider {
|
|
|
|
static var previews: some View {
|
2023-10-15 11:35:23 +00:00
|
|
|
if #available(iOS 15.0, macOS 12.0, tvOS 15.0, *) {
|
|
|
|
CommentsView()
|
|
|
|
.previewInterfaceOrientation(.landscapeRight)
|
|
|
|
.injectFixtureEnvironmentObjects()
|
|
|
|
}
|
|
|
|
|
2021-12-04 19:35:41 +00:00
|
|
|
CommentsView()
|
|
|
|
.injectFixtureEnvironmentObjects()
|
|
|
|
}
|
|
|
|
}
|