diff options
Diffstat (limited to 'Jel/Views/Item/Person/ItemPersonIconView.swift')
-rw-r--r-- | Jel/Views/Item/Person/ItemPersonIconView.swift | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/Jel/Views/Item/Person/ItemPersonIconView.swift b/Jel/Views/Item/Person/ItemPersonIconView.swift new file mode 100644 index 0000000..b839deb --- /dev/null +++ b/Jel/Views/Item/Person/ItemPersonIconView.swift @@ -0,0 +1,75 @@ +// +// 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() +//} |