Add GenreView

This commit is contained in:
Shav Kinderlehrer 2024-01-07 19:20:56 -05:00
parent b9b61fa7eb
commit 3f74421e5b
6 changed files with 81 additions and 5 deletions

View File

@ -17,6 +17,7 @@
3D13F9692B389FA300E91913 /* ViewOffsetKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3D13F9682B389FA300E91913 /* ViewOffsetKey.swift */; }; 3D13F9692B389FA300E91913 /* ViewOffsetKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3D13F9682B389FA300E91913 /* ViewOffsetKey.swift */; };
3D13F96F2B38A32500E91913 /* StickyHeaderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3D13F96E2B38A32500E91913 /* StickyHeaderView.swift */; }; 3D13F96F2B38A32500E91913 /* StickyHeaderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3D13F96E2B38A32500E91913 /* StickyHeaderView.swift */; };
3D16FC3C2B2CDFB500E6D8B3 /* DashboardLibraryView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3D16FC3B2B2CDFB500E6D8B3 /* DashboardLibraryView.swift */; }; 3D16FC3C2B2CDFB500E6D8B3 /* DashboardLibraryView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3D16FC3B2B2CDFB500E6D8B3 /* DashboardLibraryView.swift */; };
3D3816C92B4B5648006414D7 /* ItemGenresView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3D3816C82B4B5648006414D7 /* ItemGenresView.swift */; };
3D41D1F52B2C962500E58234 /* AppearancePicker.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3D41D1F42B2C962500E58234 /* AppearancePicker.swift */; }; 3D41D1F52B2C962500E58234 /* AppearancePicker.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3D41D1F42B2C962500E58234 /* AppearancePicker.swift */; };
3D41D1FA2B2CAE0000E58234 /* ItemIconView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3D41D1F92B2CAE0000E58234 /* ItemIconView.swift */; }; 3D41D1FA2B2CAE0000E58234 /* ItemIconView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3D41D1F92B2CAE0000E58234 /* ItemIconView.swift */; };
3D4C15722B3CAA670035373E /* DashboardSectionTitleView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3D4C15712B3CAA670035373E /* DashboardSectionTitleView.swift */; }; 3D4C15722B3CAA670035373E /* DashboardSectionTitleView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3D4C15712B3CAA670035373E /* DashboardSectionTitleView.swift */; };
@ -85,6 +86,7 @@
3D13F9682B389FA300E91913 /* ViewOffsetKey.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewOffsetKey.swift; sourceTree = "<group>"; }; 3D13F9682B389FA300E91913 /* ViewOffsetKey.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewOffsetKey.swift; sourceTree = "<group>"; };
3D13F96E2B38A32500E91913 /* StickyHeaderView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StickyHeaderView.swift; sourceTree = "<group>"; }; 3D13F96E2B38A32500E91913 /* StickyHeaderView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StickyHeaderView.swift; sourceTree = "<group>"; };
3D16FC3B2B2CDFB500E6D8B3 /* DashboardLibraryView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DashboardLibraryView.swift; sourceTree = "<group>"; }; 3D16FC3B2B2CDFB500E6D8B3 /* DashboardLibraryView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DashboardLibraryView.swift; sourceTree = "<group>"; };
3D3816C82B4B5648006414D7 /* ItemGenresView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ItemGenresView.swift; sourceTree = "<group>"; };
3D41D1F42B2C962500E58234 /* AppearancePicker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppearancePicker.swift; sourceTree = "<group>"; }; 3D41D1F42B2C962500E58234 /* AppearancePicker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppearancePicker.swift; sourceTree = "<group>"; };
3D41D1F92B2CAE0000E58234 /* ItemIconView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ItemIconView.swift; sourceTree = "<group>"; }; 3D41D1F92B2CAE0000E58234 /* ItemIconView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ItemIconView.swift; sourceTree = "<group>"; };
3D4C15712B3CAA670035373E /* DashboardSectionTitleView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DashboardSectionTitleView.swift; sourceTree = "<group>"; }; 3D4C15712B3CAA670035373E /* DashboardSectionTitleView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DashboardSectionTitleView.swift; sourceTree = "<group>"; };
@ -188,6 +190,7 @@
3D13F9602B37637500E91913 /* ItemMediaView.swift */, 3D13F9602B37637500E91913 /* ItemMediaView.swift */,
3DAFA8E72B38AFED00D71AD1 /* ItemInfoView.swift */, 3DAFA8E72B38AFED00D71AD1 /* ItemInfoView.swift */,
3D13F9642B37EC7A00E91913 /* ItemHeaderView.swift */, 3D13F9642B37EC7A00E91913 /* ItemHeaderView.swift */,
3D3816C82B4B5648006414D7 /* ItemGenresView.swift */,
); );
path = Item; path = Item;
sourceTree = "<group>"; sourceTree = "<group>";
@ -456,6 +459,7 @@
3D1015D92B27F57400F5C29A /* AddServerView.swift in Sources */, 3D1015D92B27F57400F5C29A /* AddServerView.swift in Sources */,
3DAFA8EA2B39039900D71AD1 /* JellyfinKitExtensions.swift in Sources */, 3DAFA8EA2B39039900D71AD1 /* JellyfinKitExtensions.swift in Sources */,
3D13F9652B37EC7A00E91913 /* ItemHeaderView.swift in Sources */, 3D13F9652B37EC7A00E91913 /* ItemHeaderView.swift in Sources */,
3D3816C92B4B5648006414D7 /* ItemGenresView.swift in Sources */,
3DAFA8EC2B394F9F00D71AD1 /* ViewConditionalMethod.swift in Sources */, 3DAFA8EC2B394F9F00D71AD1 /* ViewConditionalMethod.swift in Sources */,
3D9063CB2B279A310063DD2A /* JelApp.swift in Sources */, 3D9063CB2B279A310063DD2A /* JelApp.swift in Sources */,
3D13F9692B389FA300E91913 /* ViewOffsetKey.swift in Sources */, 3D13F9692B389FA300E91913 /* ViewOffsetKey.swift in Sources */,

View File

@ -26,7 +26,10 @@ struct DashboardLibraryView: View {
ForEach(libraries) {library in ForEach(libraries) {library in
if library.collectionType == "movies" || library.collectionType == "tvshows" { if library.collectionType == "movies" || library.collectionType == "tvshows" {
NavigationLink { NavigationLink {
LibraryDetailView(library: library) LibraryDetailView(library: library) {items in
return items
}
.navigationTitle(library.name ?? "Unknown")
} label: { } label: {
ItemIconView(item: library, height: 150) ItemIconView(item: library, height: 150)
.setAspectRatio(library.primaryImageAspectRatio) .setAspectRatio(library.primaryImageAspectRatio)

View File

@ -0,0 +1,64 @@
//
// 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 library: BaseItemDto = BaseItemDto()
var body: some View {
VStack(alignment: .leading) {
Text("Genres")
.font(.title2)
ScrollView(.horizontal) {
HStack {
ForEach(item.genres ?? [], id: \.self) {genre in
NavigationLink {
LibraryDetailView(library: library) {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)
}
}
}
}
.onAppear {
Task {
let request = Paths.getItem(userID: authState.userId ?? "", itemID: item.parentID ?? "")
do {
let res = try await jellyfinClient.send(request)
library = res.value
} catch {
}
}
}
}
}
//#Preview {
// ItemGenresView()
//}

View File

@ -9,7 +9,7 @@ import SwiftUI
import JellyfinKit import JellyfinKit
struct ItemHeaderView: View { struct ItemHeaderView: View {
@State var item: BaseItemDto var item: BaseItemDto
let overlayGradient = LinearGradient(gradient: Gradient(stops: [ let overlayGradient = LinearGradient(gradient: Gradient(stops: [
.init(color: .clear, location: 0), .init(color: .clear, location: 0),

View File

@ -9,7 +9,7 @@ import SwiftUI
import JellyfinKit import JellyfinKit
struct ItemInfoView: View { struct ItemInfoView: View {
@State var item: BaseItemDto var item: BaseItemDto
var body: some View { var body: some View {
VStack(alignment: .leading) { VStack(alignment: .leading) {

View File

@ -13,6 +13,7 @@ struct LibraryDetailView: View {
@StateObject var authState: AuthStateController = AuthStateController.shared @StateObject var authState: AuthStateController = AuthStateController.shared
@State var library: BaseItemDto @State var library: BaseItemDto
var filter: (_ items: [BaseItemDto]) -> [BaseItemDto]
@State var items: [BaseItemDto]? = [] @State var items: [BaseItemDto]? = []
@ -71,19 +72,23 @@ struct LibraryDetailView: View {
} }
} }
} }
.navigationTitle(library.name ?? "Unknown")
.onAppear { .onAppear {
Task { Task {
let params = Paths.GetItemsParameters( let params = Paths.GetItemsParameters(
userID: authState.userId, userID: authState.userId,
parentID: library.id, parentID: library.id,
fields: [.primaryImageAspectRatio] fields: [.primaryImageAspectRatio,
.genres,
.taglines,
.overview,
.parentID]
) )
let request = Paths.getItems(parameters: params) let request = Paths.getItems(parameters: params)
do { do {
let res = try await jellyfinClient.send(request) let res = try await jellyfinClient.send(request)
items = res.value.items items = res.value.items
items = self.filter(items ?? [])
items?.sort(by: {$0.name?.lowercased() ?? "" < $1.name?.lowercased() ?? ""}) items?.sort(by: {$0.name?.lowercased() ?? "" < $1.name?.lowercased() ?? ""})
loading = false loading = false
} catch { } catch {