mirror of
https://github.com/yattee/yattee.git
synced 2026-05-12 18:35:05 +00:00
Show watch progress bar on thumbnails in playlist, channel, and search views
These views rendered video thumbnails without passing watchProgress, so the progress bar was silently missing. Apply the existing pattern from SubscriptionsView: maintain a watchEntriesMap and forward watchProgress(for:) to VideoRowView/VideoCardView at each call site.
This commit is contained in:
@@ -13,12 +13,14 @@ import SwiftUI
|
||||
struct PlaylistVideoRowView: View {
|
||||
let index: Int
|
||||
let video: Video
|
||||
var watchProgress: Double? = nil
|
||||
var onRemove: (() -> Void)? = nil
|
||||
|
||||
var body: some View {
|
||||
VideoRowView(
|
||||
video: video,
|
||||
style: .regular,
|
||||
watchProgress: watchProgress,
|
||||
index: index
|
||||
)
|
||||
.videoContextMenu(
|
||||
@@ -40,9 +42,10 @@ struct PlaylistVideoRowView: View {
|
||||
|
||||
extension PlaylistVideoRowView {
|
||||
/// Initialize from a LocalPlaylistItem model.
|
||||
init(item: LocalPlaylistItem, index: Int, onRemove: @escaping () -> Void) {
|
||||
init(item: LocalPlaylistItem, index: Int, watchProgress: Double? = nil, onRemove: @escaping () -> Void) {
|
||||
self.index = index
|
||||
self.video = item.toVideo()
|
||||
self.watchProgress = watchProgress
|
||||
self.onRemove = onRemove
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,6 +92,8 @@ struct UnifiedPlaylistDetailView: View {
|
||||
@State private var hasLoadedDownloadState = false
|
||||
#endif
|
||||
|
||||
@State private var watchEntriesMap: [String: WatchEntry] = [:]
|
||||
|
||||
private var dataManager: DataManager? { appEnvironment?.dataManager }
|
||||
private var isQueueEnabled: Bool { appEnvironment?.settingsManager.queueEnabled ?? true }
|
||||
|
||||
@@ -187,6 +189,9 @@ struct UnifiedPlaylistDetailView: View {
|
||||
.task {
|
||||
await loadPlaylist()
|
||||
}
|
||||
.onReceive(NotificationCenter.default.publisher(for: .watchHistoryDidChange)) { _ in
|
||||
loadWatchEntries()
|
||||
}
|
||||
#if !os(tvOS)
|
||||
.batchDownload(coordinator: downloadCoordinator)
|
||||
.onAppear {
|
||||
@@ -663,6 +668,7 @@ struct UnifiedPlaylistDetailView: View {
|
||||
PlaylistVideoRowView(
|
||||
index: index + 1,
|
||||
video: video,
|
||||
watchProgress: watchProgress(for: video),
|
||||
onRemove: isLocal ? { removeVideo(at: index) } : nil
|
||||
)
|
||||
}
|
||||
@@ -697,6 +703,17 @@ struct UnifiedPlaylistDetailView: View {
|
||||
case .remote(let playlistID, let instance, _):
|
||||
await loadRemotePlaylist(playlistID: playlistID, instance: instance)
|
||||
}
|
||||
loadWatchEntries()
|
||||
}
|
||||
|
||||
private func loadWatchEntries() {
|
||||
watchEntriesMap = dataManager?.watchEntriesMap() ?? [:]
|
||||
}
|
||||
|
||||
private func watchProgress(for video: Video) -> Double? {
|
||||
guard let entry = watchEntriesMap[video.id.videoID] else { return nil }
|
||||
let progress = entry.progress
|
||||
return progress > 0 && progress < 1 ? progress : nil
|
||||
}
|
||||
|
||||
private func loadLocalPlaylist() {
|
||||
|
||||
Reference in New Issue
Block a user