mirror of
https://github.com/yattee/yattee.git
synced 2024-12-15 23:00:32 +05:30
40 lines
1.4 KiB
Swift
40 lines
1.4 KiB
Swift
import SwiftUI
|
|
|
|
struct CommentsView: View {
|
|
@State private var repliesID: Comment.ID?
|
|
|
|
@ObservedObject private var comments = CommentsModel.shared
|
|
|
|
var body: some View {
|
|
Group {
|
|
if comments.disabled {
|
|
NoCommentsView(text: "Comments are disabled".localized(), systemImage: "xmark.circle.fill")
|
|
} else if comments.loaded && comments.all.isEmpty {
|
|
NoCommentsView(text: "No comments".localized(), systemImage: "0.circle.fill")
|
|
} else if !comments.loaded {
|
|
PlaceholderProgressView()
|
|
} else {
|
|
let last = comments.all.last
|
|
LazyVStack {
|
|
ForEach(comments.all) { comment in
|
|
CommentView(comment: comment, repliesID: $repliesID)
|
|
.onAppear {
|
|
comments.loadNextPageIfNeeded(current: comment)
|
|
}
|
|
.borderBottom(height: comment != last ? 0.5 : 0, color: Color("ControlsBorderColor"))
|
|
}
|
|
}
|
|
}
|
|
}
|
|
.padding(.horizontal)
|
|
}
|
|
}
|
|
|
|
struct CommentsView_Previews: PreviewProvider {
|
|
static var previews: some View {
|
|
CommentsView()
|
|
.previewInterfaceOrientation(.landscapeRight)
|
|
.injectFixtureEnvironmentObjects()
|
|
}
|
|
}
|