49 lines
1.3 KiB
Swift
49 lines
1.3 KiB
Swift
import Foundation
|
|
import Adwaita
|
|
import LuminateCore
|
|
|
|
struct PosterCell: View {
|
|
|
|
var item: Components.Schemas.BaseItemDto
|
|
var client: JellyfinClient
|
|
@State private var imageData: Data?
|
|
|
|
var view: Body {
|
|
VStack {
|
|
if let data = imageData {
|
|
Picture()
|
|
.data(data)
|
|
.frame(maxWidth: 150)
|
|
.frame(maxHeight: 225)
|
|
} else {
|
|
Box(spacing: 0) {}
|
|
.frame(maxWidth: 150)
|
|
.frame(maxHeight: 225)
|
|
.style("card")
|
|
}
|
|
Text(item.name ?? "")
|
|
.style("body")
|
|
.halign(.center)
|
|
.frame(maxWidth: 150)
|
|
}
|
|
.onAppear {
|
|
loadImage()
|
|
}
|
|
}
|
|
|
|
private func loadImage() {
|
|
guard let tag = item.primaryImageTag,
|
|
let itemId = item.id else { return }
|
|
Task {
|
|
let url = await client.imageURL(
|
|
itemId: itemId,
|
|
imageType: .primary,
|
|
tag: tag,
|
|
maxWidth: 300
|
|
)
|
|
guard let url else { return }
|
|
let service = ImageService()
|
|
imageData = try? await service.loadImage(url: url)
|
|
}
|
|
}
|
|
}
|