jel/Jel/Views/Dashboard/DashboardLibraryView.swift

60 lines
1.5 KiB
Swift

//
// 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) {items in
return items
}
.navigationTitle(library.name ?? "Unknown")
} label: {
ItemIconView(item: library, height: 150)
.setAspectRatio(library.primaryImageAspectRatio)
.showCaption()
}
.buttonStyle(PlainButtonStyle())
}
}.padding(.horizontal)
}
}
.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()
//}