1
0
mirror of https://github.com/yattee/yattee.git synced 2024-12-13 13:50:32 +05:30
yattee/Shared/Player/Video Details/CommentsView.swift

51 lines
1.8 KiB
Swift
Raw Normal View History

2021-12-05 01:05:41 +05:30
import SwiftUI
struct CommentsView: View {
@State private var repliesID: Comment.ID?
@State private var availableWidth = 0.0
2021-12-05 01:05:41 +05:30
@ObservedObject private var comments = CommentsModel.shared
2021-12-05 01:05:41 +05:30
var body: some View {
Group {
if comments.disabled {
2022-09-28 21:15:05 +05:30
NoCommentsView(text: "Comments are disabled".localized(), systemImage: "xmark.circle.fill")
} else if comments.loaded && comments.all.isEmpty {
2022-09-28 21:15:05 +05:30
NoCommentsView(text: "No comments".localized(), systemImage: "0.circle.fill")
} else if !comments.loaded {
PlaceholderProgressView()
} else {
LazyVStack {
2022-01-05 21:42:32 +05:30
ForEach(comments.all) { comment in
CommentView(comment: comment, repliesID: $repliesID, availableWidth: availableWidth)
2022-01-05 21:42:32 +05:30
.onAppear {
comments.loadNextPageIfNeeded(current: comment)
}
.borderBottom(height: comment != comments.all.last ? 0.5 : 0, color: Color("ControlsBorderColor"))
2021-12-05 01:05:41 +05:30
}
}
.background(GeometryReader { geometry in
Color.clear
.onAppear {
self.availableWidth = Double(geometry.size.width)
}
})
2021-12-05 01:05:41 +05:30
}
}
.padding(.horizontal)
}
2021-12-05 01:05:41 +05:30
}
struct CommentsView_Previews: PreviewProvider {
static var previews: some View {
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()
}
}