jel/Jel/Views/Item/Person/ItemPersonIconView.swift

76 lines
1.9 KiB
Swift

//
// ItemPersonIconView.swift
// Jel
//
// Created by zerocool on 1/8/24.
//
import SwiftUI
import JellyfinKit
import NukeUI
struct ItemPersonIconPlaceholderView: View {
var body: some View {
ZStack {
Color(uiColor: UIColor.secondarySystemBackground)
Image(systemName: "person.fill")
.resizable()
.aspectRatio(contentMode: .fit)
.padding()
.foregroundStyle(Color(uiColor: UIColor.secondarySystemFill))
}
.frame(height: 150)
.clipShape(RoundedRectangle(cornerRadius: 5))
}
}
struct ItemPersonIconView: View {
@StateObject var authState: AuthStateController = AuthStateController.shared
@EnvironmentObject var jellyfinClient: JellyfinClientController
var person: BaseItemPerson
@State var personImageUrl: URL?
var body: some View {
VStack {
LazyImage(url: personImageUrl) {state in
if let image = state.image {
image
.resizable()
.aspectRatio(contentMode: .fit)
.clipShape(RoundedRectangle(cornerRadius: 5))
} else {
ItemPersonIconPlaceholderView()
}
}
.frame(height: 170)
VStack(alignment: .leading) {
Text(person.name ?? "---")
.font(.footnote)
.lineLimit(nil)
Text(person.role ?? "---")
.font(.caption)
.foregroundStyle(Color(uiColor: UIColor.secondaryLabel))
.fixedSize(horizontal: false, vertical: true)
.lineLimit(nil)
}
.multilineTextAlignment(.leading)
}
.frame(width: 100)
.onAppear {
Task {
let request = Paths.getItemImage(itemID: person.id ?? "", imageType: "Primary")
let serverUrl = jellyfinClient.getUrl()
personImageUrl = serverUrl?.appending(path: request.url?.absoluteString ?? "")
}
}
}
}
//#Preview {
// ItemPersonView()
//}