82 lines
2.4 KiB
Swift
82 lines
2.4 KiB
Swift
import Adwaita
|
|
import Foundation
|
|
import LuminateCore
|
|
import LuminateDI
|
|
|
|
struct HomePosterCell: View {
|
|
|
|
var item: Components.Schemas.BaseItemDto
|
|
@Injected(\.client) var client
|
|
@Injected(\.pageAnimationTracker) var pageAnimationTracker
|
|
@State private var imageData: Data?
|
|
|
|
var view: Body {
|
|
VStack {
|
|
if let data = imageData {
|
|
Picture()
|
|
.contentFit(.cover)
|
|
.data(data)
|
|
.frame(minWidth: 200, minHeight: 300)
|
|
.frame(maxWidth: 200)
|
|
.frame(maxHeight: 300)
|
|
} else {
|
|
Box(spacing: 0) {}
|
|
.frame(minWidth: 200, minHeight: 300)
|
|
.frame(maxWidth: 200)
|
|
.frame(maxHeight: 300)
|
|
.card()
|
|
}
|
|
VStack(spacing: 0) {
|
|
if let title = item.name, !title.isEmpty {
|
|
Text(item.name ?? "")
|
|
.ellipsize()
|
|
.heading()
|
|
.halign(.center)
|
|
.frame(maxWidth: 200)
|
|
}
|
|
let subtitle = item.yearString
|
|
if !subtitle.isEmpty {
|
|
Text(subtitle)
|
|
.ellipsize()
|
|
.caption()
|
|
.dimLabel()
|
|
.halign(.center)
|
|
.frame(maxWidth: 200)
|
|
}
|
|
}
|
|
.padding(6, .vertical)
|
|
.padding(12, .horizontal)
|
|
}
|
|
.onAppear {
|
|
Idle {
|
|
loadImage()
|
|
}
|
|
}
|
|
.overflow(.hidden)
|
|
.card()
|
|
}
|
|
|
|
private func loadImage() {
|
|
guard let tag = item.primaryImageTag,
|
|
let itemId = item.seriesId ?? item.id
|
|
else { return }
|
|
Task {
|
|
guard
|
|
let url = await client.imageURL(
|
|
itemId: itemId,
|
|
imageType: .primary,
|
|
tag: tag,
|
|
maxWidth: 400
|
|
)
|
|
else { return }
|
|
let service = ImageService()
|
|
let data = try? await service.loadImage(url: url)
|
|
|
|
if pageAnimationTracker.isAnimating {
|
|
_imageData.rawValue = data
|
|
} else {
|
|
imageData = data
|
|
}
|
|
}
|
|
}
|
|
}
|