diff options
Diffstat (limited to 'Jel/Views/Library/LibraryIconView.swift')
-rw-r--r-- | Jel/Views/Library/LibraryIconView.swift | 57 |
1 files changed, 27 insertions, 30 deletions
diff --git a/Jel/Views/Library/LibraryIconView.swift b/Jel/Views/Library/LibraryIconView.swift index 6a7d5ae..71c6e14 100644 --- a/Jel/Views/Library/LibraryIconView.swift +++ b/Jel/Views/Library/LibraryIconView.swift @@ -7,49 +7,46 @@ import SwiftUI import JellyfinKit +import NukeUI struct LibraryIconView: View { @EnvironmentObject var jellyfinClient: JellyfinClientController - @State var library: BaseItemDto + var library: BaseItemDto - @State var loadingImage: Bool = true - @State var imageType: String = "Primary" + var imageType: String = "Primary" var width: CGFloat? var height: CGFloat? @State var blurHashImage: UIImage = UIImage() @State var imageUrl: URL? var body: some View { - AsyncImage(url: imageUrl) {image in - VStack { - image - .resizable() - .aspectRatio(contentMode: .fit) - .frame(width: width, height: height) - .clipShape(RoundedRectangle(cornerRadius: 3)) - Text(library.name ?? "Unknown") - .font(.subheadline) + VStack { + LazyImage(url: imageUrl) {state in + if let image = state.image { + image + .resizable() + } else if state.error != nil { + Color.red + } else { + Image(uiImage: blurHashImage) + .resizable() + } } - } placeholder: { - VStack { - Image(uiImage: blurHashImage) - .resizable() - .aspectRatio(contentMode: .fit) - .frame(width: width, height: height) - .clipShape(RoundedRectangle(cornerRadius: 3)) - Text(library.name ?? "Unknown") - .font(.subheadline) - } - } - - .onAppear { - let blurhash = library.imageBlurHashes?.primary?[library.imageTags?[imageType] ?? ""] ?? "" - blurHashImage = UIImage(blurHash: blurhash, size: CGSize(width: 32, height: 32)) ?? UIImage() + .aspectRatio(contentMode: .fit) + .frame(width: width, height: height) + .clipShape(RoundedRectangle(cornerRadius: 5)) - let imageId = library.id ?? "" - let request = Paths.getItemImage(itemID: imageId, imageType: imageType) - imageUrl = jellyfinClient.getUrl()?.appending(path: request.url?.absoluteString ?? "") + Text(library.name ?? "Unknown") + .font(.subheadline) + .onAppear { + let blurhash = library.imageBlurHashes?.primary?[library.imageTags?[imageType] ?? ""] ?? "" + blurHashImage = UIImage(blurHash: blurhash, size: CGSize(width: 16, height: 16)) ?? UIImage() + + let imageId = library.id ?? "" + let request = Paths.getItemImage(itemID: imageId, imageType: imageType) + imageUrl = jellyfinClient.getUrl()?.appending(path: request.url?.absoluteString ?? "") + } } } } |