Fix thumbnails

This commit is contained in:
Arkadiusz Fal 2022-12-11 14:00:46 +01:00
parent 5e0f13cace
commit e3daa738ce
2 changed files with 9 additions and 28 deletions

View File

@ -3,38 +3,18 @@ import SwiftUI
struct ThumbnailView: View { struct ThumbnailView: View {
var url: URL? var url: URL?
@ObservedObject private var thumbnails = ThumbnailsModel.shared
@ObservedObject private var imageManager = ImageManager()
private var thumbnails = ThumbnailsModel.shared
init(url: URL? = nil) {
self.url = url
}
var body: some View { var body: some View {
Group { WebImage(url: url)
if imageManager.image != nil { .resizable()
Group { .onFailure { _ in
#if os(macOS) if let url {
Image(nsImage: imageManager.image!) thumbnails.insertUnloadable(url)
.resizable()
#else
Image(uiImage: imageManager.image!)
.resizable()
#endif
} }
} else { }
.placeholder {
Rectangle().fill(Color("PlaceholderColor")) Rectangle().fill(Color("PlaceholderColor"))
} }
}
.onAppear {
guard let url else { return }
self.imageManager.setOnFailure { _ in
self.thumbnails.insertUnloadable(url)
}
self.imageManager.load(url: url)
}
.onDisappear { self.imageManager.cancel() }
} }
} }

View File

@ -52,6 +52,7 @@ struct VideoCell: View {
.contextMenu { .contextMenu {
VideoContextMenuView(video: video) VideoContextMenuView(video: video)
} }
.id(video.videoID)
} }
private var thumbnailRoundingCornerRadius: Double { private var thumbnailRoundingCornerRadius: Double {