summaryrefslogtreecommitdiff
path: root/Jel/Views/Library/Item/Person/ItemPersonIconView.swift
blob: a6e5161c1db0cc6173377a898615d6ff062069cc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
//
//  ItemPersonIconView.swift
//  Jel
//
//  Created by zerocool on 1/8/24.
//

import SwiftUI
import JellyfinKit
import NukeUI

struct ItemPersonIconPlaceholderView: View {
  var body: some View {
    VStack {
      Image(systemName: "person")
        .resizable()
        .padding()
        .scaledToFit()
    }
  }
}

struct ItemPersonIconView: View {
  @StateObject var authState: AuthStateController = AuthStateController.shared
  @EnvironmentObject var jellyfinClient: JellyfinClientController
  
  var person: BaseItemPerson
  
  @State var personImageUrl: URL?
  @State var loading: Bool = true
  
  var body: some View {
    VStack() {
      LazyImage(url: personImageUrl) {state in
        if let image = state.image {
          image
            .resizable()
            .clipShape(RoundedRectangle(cornerRadius: 5))
        } else {
          ItemPersonIconPlaceholderView()
        }
      }
      .aspectRatio(contentMode: .fit)
      .frame(width: 100, height: 170)
      
      VStack {
        Text(person.name ?? "---")
          .font(.callout)
        Text(person.role ?? "---")
          .font(.caption)
          .foregroundStyle(.gray)
      }
      .frame(width: 100)
    }
    //    .redacted(reason: loading ? .placeholder : [])
    .onAppear {
      Task {
        let request = Paths.getItemImage(itemID: person.id ?? "", imageType: "Primary")
        
        let serverUrl = jellyfinClient.getUrl()
        personImageUrl = serverUrl?.appending(path: request.url?.absoluteString ?? "")
        //        loading = false
      }
    }
  }
}

//#Preview {
//    ItemPersonView()
//}