jel/Jel/Views/Library/Item/ItemGenresView.swift

74 lines
1.8 KiB
Swift

//
// ItemGenresView.swift
// Jel
//
// Created by zerocool on 1/7/24.
//
import SwiftUI
import JellyfinKit
struct ItemGenresView: View {
@EnvironmentObject var jellyfinClient: JellyfinClientController
@StateObject var authState: AuthStateController = AuthStateController.shared
var item: BaseItemDto
@State var libraryItems: [BaseItemDto]? = []
var body: some View {
VStack(alignment: .leading) {
Text("Genres")
.font(.title2)
.padding(.horizontal)
ScrollView(.horizontal) {
HStack {
ForEach(item.genres ?? [], id: \.self) {genre in
NavigationLink {
LibraryDetailView(library: BaseItemDto(name: genre), items: libraryItems) {items in
var matchingItems: [BaseItemDto] = []
for item in items {
if (item.genres ?? []).contains(genre) {
matchingItems.append(item)
}
}
return matchingItems
}
.navigationTitle(genre)
} label: {
Text(genre)
}
.buttonStyle(.bordered)
.clipShape(.capsule)
}
}
.padding(.horizontal)
}
.scrollIndicators(.hidden)
}
.onAppear {
Task {
let parameters = Paths.GetItemsParameters(
userID: authState.userId ?? "",
isRecursive: true,
includeItemTypes: [.movie, .series],
genres: item.genres ?? []
)
let request = Paths.getItems(parameters: parameters)
do {
let res = try await jellyfinClient.send(request)
libraryItems = res.value.items ?? []
} catch {
}
}
}
}
}
//#Preview {
// ItemGenresView()
//}