summaryrefslogtreecommitdiff
path: root/Jel/Views/Dashboard/DashboardLibraryView.swift
blob: 57ffa50e3deea7e46d4a8595425f078574f2b1bf (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
//
//  DashboardLibraryView.swift
//  Jel
//
//  Created by zerocool on 12/15/23.
//

import SwiftUI
import JellyfinKit

struct DashboardLibraryView: View {
  @EnvironmentObject var jellyfinClient: JellyfinClientController
  
  @StateObject var authState: AuthStateController = AuthStateController.shared
  
  @State var libraries: [BaseItemDto] = []
  @State var loading: Bool = true
  
  var body: some View {
    if loading {
      ProgressView()
        .progressViewStyle(.circular)
    }
    ScrollView(.horizontal, showsIndicators: false) {
      LazyHStack {
        ForEach(libraries) {library in
          if library.collectionType == "movies" || library.collectionType == "tvshows" {
            NavigationLink {
              LibraryDetailView(library: library)
            } label: {
              LibraryIconView(library: library, height: 150)
                .padding()
            }
            .buttonStyle(PlainButtonStyle())
          }
        }
      }
    }
    .onAppear {
      Task {
        do {
          let request = Paths.getUserViews(userID: authState.userId ?? "")
          if let results = try await jellyfinClient.send(request).value.items {
            libraries = results
          }
          loading = false
        } catch {
        }
      }
    }}
}

//#Preview {
//  LibraryView()
//}