// // LibraryIconView.swift // Jel // // Created by zerocool on 12/15/23. // import SwiftUI import JellyfinKit struct LibraryIconView: View { @EnvironmentObject var jellyfinClient: JellyfinClientController @State var library: BaseItemDto @State var loadingImage: Bool = true @State 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) } } 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() let imageId = library.id ?? "" let request = Paths.getItemImage(itemID: imageId, imageType: imageType) imageUrl = jellyfinClient.getUrl()?.appending(path: request.url?.absoluteString ?? "") } } } //#Preview { // LibraryIconView(library: BaseItemDto()) //}