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

76 lines
1.9 KiB
Swift
Raw Normal View History

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