yattee/Shared/Player/Video Details/CommentsView.swift

40 lines
1.4 KiB
Swift
Raw Normal View History

2021-12-04 19:35:41 +00:00
import SwiftUI
struct CommentsView: View {
@State private var repliesID: Comment.ID?
@ObservedObject private var comments = CommentsModel.shared
2021-12-04 19:35:41 +00:00
var body: some View {
Group {
if comments.disabled {
2022-09-28 15:45:05 +00:00
NoCommentsView(text: "Comments are disabled".localized(), systemImage: "xmark.circle.fill")
} else if comments.loaded && comments.all.isEmpty {
2022-09-28 15:45:05 +00:00
NoCommentsView(text: "No comments".localized(), systemImage: "0.circle.fill")
} else if !comments.loaded {
PlaceholderProgressView()
} else {
2022-01-05 16:12:32 +00:00
let last = comments.all.last
LazyVStack {
2022-01-05 16:12:32 +00:00
ForEach(comments.all) { comment in
CommentView(comment: comment, repliesID: $repliesID)
.onAppear {
comments.loadNextPageIfNeeded(current: comment)
}
2022-06-24 23:39:29 +00:00
.borderBottom(height: comment != last ? 0.5 : 0, color: Color("ControlsBorderColor"))
2021-12-04 19:35:41 +00:00
}
}
}
}
.padding(.horizontal)
}
2021-12-04 19:35:41 +00:00
}
struct CommentsView_Previews: PreviewProvider {
static var previews: some View {
CommentsView()
2023-07-01 16:38:11 +00:00
.previewInterfaceOrientation(.landscapeRight)
2021-12-04 19:35:41 +00:00
.injectFixtureEnvironmentObjects()
}
}