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

74 lines
1.8 KiB
Swift
Raw Normal View History

2024-01-08 00:20:56 +00:00
//
// 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]? = []
2024-01-08 00:20:56 +00:00
var body: some View {
VStack(alignment: .leading) {
Text("Genres")
.font(.title2)
2024-01-09 17:32:06 +00:00
.padding(.horizontal)
2024-01-08 00:20:56 +00:00
ScrollView(.horizontal) {
HStack {
ForEach(item.genres ?? [], id: \.self) {genre in
NavigationLink {
LibraryDetailView(library: BaseItemDto(name: genre), items: libraryItems) {items in
2024-01-08 00:20:56 +00:00
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)
}
}
2024-01-09 17:32:06 +00:00
.padding(.horizontal)
2024-01-08 00:20:56 +00:00
}
2024-01-09 17:32:06 +00:00
.scrollIndicators(.hidden)
2024-01-08 00:20:56 +00:00
}
.onAppear {
Task {
let parameters = Paths.GetItemsParameters(
userID: authState.userId ?? "",
isRecursive: true,
includeItemTypes: [.movie, .series],
genres: item.genres ?? []
)
let request = Paths.getItems(parameters: parameters)
2024-01-08 00:20:56 +00:00
do {
let res = try await jellyfinClient.send(request)
libraryItems = res.value.items ?? []
2024-01-08 00:20:56 +00:00
} catch {
}
}
}
}
}
//#Preview {
// ItemGenresView()
//}