1
0
mirror of https://github.com/yattee/yattee.git synced 2024-12-13 22:00:31 +05:30
yattee/Shared/Player/CommentsView.swift

62 lines
2.0 KiB
Swift
Raw Normal View History

2021-12-05 01:05:41 +05:30
import SwiftUI
struct CommentsView: View {
2022-01-05 21:42:32 +05:30
var embedInScrollView = false
2021-12-05 01:05:41 +05:30
@State private var repliesID: Comment.ID?
@EnvironmentObject<CommentsModel> private var comments
var body: some View {
Group {
if comments.disabled {
2022-01-05 21:42:32 +05:30
NoCommentsView(text: "Comments are disabled", systemImage: "xmark.circle.fill")
} else if comments.loaded && comments.all.isEmpty {
2022-01-05 21:42:32 +05:30
NoCommentsView(text: "No comments", systemImage: "0.circle.fill")
} else if !comments.loaded {
PlaceholderProgressView()
2021-12-18 01:16:49 +05:30
.onAppear {
comments.load()
}
} else {
2022-01-05 21:42:32 +05:30
let last = comments.all.last
let commentsStack = LazyVStack {
ForEach(comments.all) { comment in
CommentView(comment: comment, repliesID: $repliesID)
.onAppear {
comments.loadNextPageIfNeeded(current: comment)
}
2022-01-05 21:42:32 +05:30
.padding(.bottom, comment == last ? 5 : 0)
2022-01-05 21:42:32 +05:30
if comment != last {
Divider()
.padding(.vertical, 5)
2021-12-05 01:05:41 +05:30
}
}
}
2022-01-05 21:42:32 +05:30
if embedInScrollView {
ScrollView(.vertical, showsIndicators: false) {
commentsStack
}
} else {
commentsStack
}
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()
}
CommentsView()
.injectFixtureEnvironmentObjects()
}
}