summaryrefslogtreecommitdiff
path: root/Jel/Views/Item/Series/ItemSeriesEpisodesView.swift
blob: f0d95cf006e4dc5201c883ca3bd98ff73663026a (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
//
//  ItemSeriesEpisodesView.swift
//  Jel
//
//  Created by zerocool on 2/14/24.
//

import SwiftUI
import JellyfinKit

struct ItemSeriesEpisodesView: View {
  @EnvironmentObject var jellyfinClient: JellyfinClientController
  @ObservedObject var authState: AuthStateController = AuthStateController.shared
  
  var item: BaseItemDto
  
  @State var episodeItems: [BaseItemDto] = []
  @State var loading: Bool = true
  
  var body: some View {
    LazyVStack(alignment: .leading) {
      ForEach(episodeItems) {episode in
        ItemSeriesEpisodeIconView(item: episode)
      }
    }
    .if(loading) {view in
      view
        .redacted(reason: .placeholder)
    }
    .onChange(of: item) {
      self.loadEpisodes()
    }
    .onAppear {
      self.loadEpisodes()
    }
  }
  
  func loadEpisodes() {
    Task {
      let parameters = Paths.GetItemsParameters(
        userID: authState.userId,
        parentID: item.id ?? ""
      )
      let req = Paths.getItems(parameters: parameters)
      
      do {
        let res = try await jellyfinClient.send(req)
        episodeItems = res.value.items ?? []
        loading = false
      } catch {}
    }
  }}

//#Preview {
//    ItemSeriesEpisodesView()
//}