jel/Jel/Views/Dashboard/DashboardLibraryView.swift

60 lines
1.5 KiB
Swift
Raw Normal View History

//
2023-12-23 05:53:44 +00:00
// DashboardLibraryView.swift
// Jel
//
// Created by zerocool on 12/15/23.
//
import SwiftUI
import JellyfinKit
2023-12-23 05:53:44 +00:00
struct DashboardLibraryView: View {
@EnvironmentObject var jellyfinClient: JellyfinClientController
@StateObject var authState: AuthStateController = AuthStateController.shared
@State var libraries: [BaseItemDto] = []
2023-12-23 16:14:53 +00:00
@State var loading: Bool = true
2023-12-25 05:41:45 +00:00
var body: some View {
2023-12-23 16:14:53 +00:00
if loading {
ProgressView()
.progressViewStyle(.circular)
}
ScrollView(.horizontal, showsIndicators: false) {
LazyHStack {
ForEach(libraries) {library in
if library.collectionType == "movies" || library.collectionType == "tvshows" {
2023-12-23 05:53:44 +00:00
NavigationLink {
2024-01-08 00:20:56 +00:00
LibraryDetailView(library: library) {items in
return items
}
.navigationTitle(library.name ?? "Unknown")
2023-12-23 05:53:44 +00:00
} label: {
ItemIconView(item: library, height: 150)
.setAspectRatio(library.primaryImageAspectRatio)
2024-01-08 17:57:25 +00:00
.showCaption()
2023-12-23 05:53:44 +00:00
}
2023-12-23 16:14:53 +00:00
.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
}
2023-12-23 16:14:53 +00:00
loading = false
} catch {
}
}
2023-12-23 16:14:53 +00:00
}}
}
//#Preview {
// LibraryView()
//}