1
0
mirror of https://github.com/yattee/yattee.git synced 2024-12-15 06:40:32 +05:30
yattee/Shared/Home/HistoryView.swift

53 lines
1.5 KiB
Swift
Raw Normal View History

2022-11-09 19:04:04 +05:30
import SwiftUI
struct HistoryView: View {
2022-11-15 16:52:27 +05:30
var limit = 10
2022-11-09 19:04:04 +05:30
@FetchRequest(sortDescriptors: [.init(key: "watchedAt", ascending: false)])
var watches: FetchedResults<Watch>
@ObservedObject private var player = PlayerModel.shared
2022-11-09 19:04:04 +05:30
var body: some View {
LazyVStack {
2022-11-11 23:20:13 +05:30
if visibleWatches.isEmpty {
VStack(spacing: 20) {
2022-11-11 23:20:13 +05:30
HStack {
Image(systemName: "clock")
Text("Playback history is empty")
}.foregroundColor(.secondary)
2022-11-09 19:04:04 +05:30
}
2022-11-11 23:20:13 +05:30
} else {
ForEach(visibleWatches, id: \.videoID) { watch in
2022-12-15 16:39:36 +05:30
let video = player.historyVideo(watch.videoID) ?? watch.video
ContentItemView(item: .init(video: video))
.environment(\.listingStyle, .list)
.contextMenu {
VideoContextMenuView(video: video)
}
2022-11-09 19:04:04 +05:30
}
}
}
2022-11-14 23:16:50 +05:30
.onAppear {
visibleWatches
.forEach(player.loadHistoryVideoDetails)
}
2022-11-11 23:20:13 +05:30
#if os(tvOS)
.padding(.horizontal, 40)
#else
.padding(.horizontal, 15)
#endif
2022-11-09 19:04:04 +05:30
}
private var visibleWatches: [Watch] {
Array(watches.filter { $0.videoID != player.currentVideo?.videoID }.prefix(limit))
}
}
struct HistoryView_Previews: PreviewProvider {
static var previews: some View {
HistoryView()
}
}