jel/Jel/Views/Dashboard/DashboardLibraryView.swift

57 lines
1.4 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 {
LibraryDetailView(library: library)
} label: {
2023-12-23 16:14:53 +00:00
LibraryIconView(library: library, height: 150)
.setAspectRatio(library.primaryImageAspectRatio)
2023-12-23 05:53:44 +00:00
.padding()
}
2023-12-23 16:14:53 +00:00
.buttonStyle(PlainButtonStyle())
}
}
}
}
.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()
//}