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
|
2024-01-08 02:21:36 +00:00
|
|
|
@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 {
|
2024-01-08 02:21:36 +00:00
|
|
|
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 {
|
2024-01-08 02:21:36 +00:00
|
|
|
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)
|
2024-01-08 02:21:36 +00:00
|
|
|
libraryItems = res.value.items ?? []
|
2024-01-08 00:20:56 +00:00
|
|
|
} catch {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//#Preview {
|
|
|
|
// ItemGenresView()
|
|
|
|
//}
|