summaryrefslogtreecommitdiff
path: root/Jel/Views/Library/Item/ItemMediaView.swift
blob: 38c242d89f9aa9a275184fe6a81f340751f583f8 (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
71
72
73
74
75
76
77
//
//  ItemMediaView.swift
//  Jel
//
//  Created by zerocool on 12/23/23.
//

import SwiftUI
import JellyfinKit

struct ItemMediaView: View {
  @EnvironmentObject var jellyfinClient: JellyfinClientController
  @StateObject var authState: AuthStateController = AuthStateController.shared
  
  @State var item: BaseItemDto
  @State var loading: Bool = true
  
  @State var navigationTitle: String = ""
  
  var body: some View {
    VStack {
      if loading {
        ProgressView()
          .progressViewStyle(.circular)
      } else {
        ScrollView {
          ItemHeaderView(item: item)
            .padding(.bottom)
            .background {
              GeometryReader {geo in
                EmptyView()
                  .onChange(of: geo.frame(in: .global).minY) {
                    let minY = geo.frame(in: .global).minY
                    if minY < 0 {
                      navigationTitle = item.name ?? ""
                    } else {
                      navigationTitle = ""
                    }
                  }
              }
            }
          
          VStack(alignment: .leading) {
            Text(item.taglines?.count ?? 0 > 0 ? item.taglines?[0] ?? "" : "")
              .font(.headline)
              .frame(maxWidth: .infinity, alignment: .leading)
              .padding(.bottom)
            
            Text(item.overview ?? "---")
          }
          .padding()
        }
      }
    }
    .toolbarRole(.editor)
    .navigationBarTitleDisplayMode(.inline)
    .navigationTitle(navigationTitle)
    .ignoresSafeArea()
    .scrollIndicators(.hidden)
    .onAppear {
      Task {
        do {
          let request = Paths.getItem(userID: authState.userId ?? "", itemID: item.id ?? "")
          let response = try await jellyfinClient.send(request)
          item = response.value
          loading = false
        } catch {
        }
      }
    }
  }
}

//#Preview {
//  ItemMovieView(item: BaseItemDto())

//}