67 lines
1.7 KiB
Swift
67 lines
1.7 KiB
Swift
//
|
|
// PosterCell.swift
|
|
// LuminateUI
|
|
//
|
|
// Created by Brendan Szymanski on 6/5/26.
|
|
//
|
|
|
|
@preconcurrency import Adwaita
|
|
import Foundation
|
|
import LuminateCore
|
|
import LuminateDI
|
|
|
|
struct PosterCell: View {
|
|
|
|
var item: Components.Schemas.BaseItemDto
|
|
var client: JellyfinClient
|
|
@Injected(\.pageAnimationTracker) var pageAnimationTracker
|
|
@State private nonisolated(unsafe) 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)
|
|
.card()
|
|
}
|
|
Text(item.name ?? "")
|
|
.body()
|
|
.halign(.center)
|
|
.frame(maxWidth: 150)
|
|
}
|
|
.onAppear {
|
|
Idle {
|
|
loadImage()
|
|
}
|
|
}
|
|
}
|
|
|
|
private func loadImage() {
|
|
guard let tag = item.primaryImageTag,
|
|
let itemId = item.id
|
|
else { return }
|
|
Task { [self] in
|
|
let url = await client.imageURL(
|
|
itemId: itemId,
|
|
imageType: .primary,
|
|
tag: tag,
|
|
maxWidth: 300
|
|
)
|
|
guard let url else { return }
|
|
let service = ImageService()
|
|
let data = try? await service.loadImage(url: url)
|
|
|
|
if pageAnimationTracker.isAnimating {
|
|
_imageData.rawValue = data
|
|
} else {
|
|
imageData = data
|
|
}
|
|
}
|
|
}
|
|
}
|