From 885615d1dd029138700c36bb8b23d211cf713811 Mon Sep 17 00:00:00 2001 From: Shav Kinderlehrer Date: Sat, 23 Dec 2023 00:53:44 -0500 Subject: Refactor LibraryIconView --- Jel/Views/Dashboard/DashboardLibraryView.swift | 48 +++++++++++++++++++++++ Jel/Views/Dashboard/DashboardView.swift | 10 ++--- Jel/Views/Dashboard/Library/LibraryIconView.swift | 38 ------------------ Jel/Views/Dashboard/Library/LibraryView.swift | 44 --------------------- 4 files changed, 53 insertions(+), 87 deletions(-) create mode 100644 Jel/Views/Dashboard/DashboardLibraryView.swift delete mode 100644 Jel/Views/Dashboard/Library/LibraryIconView.swift delete mode 100644 Jel/Views/Dashboard/Library/LibraryView.swift (limited to 'Jel/Views/Dashboard') diff --git a/Jel/Views/Dashboard/DashboardLibraryView.swift b/Jel/Views/Dashboard/DashboardLibraryView.swift new file mode 100644 index 0000000..98c92c0 --- /dev/null +++ b/Jel/Views/Dashboard/DashboardLibraryView.swift @@ -0,0 +1,48 @@ +// +// DashboardLibraryView.swift +// Jel +// +// Created by zerocool on 12/15/23. +// + +import SwiftUI +import JellyfinKit + +struct DashboardLibraryView: View { + @EnvironmentObject var jellyfinClient: JellyfinClientController + + @StateObject var authState: AuthStateController = AuthStateController.shared + + @State var libraries: [BaseItemDto] = [] + var body: some View { + ScrollView(.horizontal, showsIndicators: false) { + HStack { + ForEach(libraries) {library in + if library.collectionType == "movies" || library.collectionType == "tvshows" { + NavigationLink { + LibraryDetailView(library: library) + } label: { + LibraryIconView(library: library, height: 200) + .padding() + } + } + } + } + } + .onAppear { + Task { + do { + let request = Paths.getUserViews(userID: authState.userId ?? "") + if let results = try await jellyfinClient.send(request).value.items { + libraries = results + } + } catch { + } + } + } + } +} + +//#Preview { +// LibraryView() +//} diff --git a/Jel/Views/Dashboard/DashboardView.swift b/Jel/Views/Dashboard/DashboardView.swift index 2658180..50d3538 100644 --- a/Jel/Views/Dashboard/DashboardView.swift +++ b/Jel/Views/Dashboard/DashboardView.swift @@ -14,10 +14,10 @@ struct DashboardView: View { var body: some View { NavigationStack { VStack { - LibraryView() + DashboardLibraryView() } .toolbar { - ToolbarItem { + ToolbarItem(placement: .topBarTrailing) { Button { showingSettingsSheet.toggle() } label: { @@ -32,6 +32,6 @@ struct DashboardView: View { } } -#Preview { - DashboardView() -} +//#Preview { +// DashboardView() +//} diff --git a/Jel/Views/Dashboard/Library/LibraryIconView.swift b/Jel/Views/Dashboard/Library/LibraryIconView.swift deleted file mode 100644 index 0131ff7..0000000 --- a/Jel/Views/Dashboard/Library/LibraryIconView.swift +++ /dev/null @@ -1,38 +0,0 @@ -// -// LibraryIconView.swift -// Jel -// -// Created by zerocool on 12/15/23. -// - -import SwiftUI -import JellyfinKit -import BlurHashKit - -struct LibraryIconView: View { - @EnvironmentObject var jellyfinClient: JellyfinClientController - - @State var library: BaseItemDto - @State var loadingImage: Bool = true - - @State var loadedImageBinaryData: Data? - - var body: some View { - VStack { - AsyncImageView(imageId: library.id ?? "", - blurhash: library.imageBlurHashes?.primary?[library.imageTags?["Primary"] ?? ""] ?? "", - imageType: "Primary") - .aspectRatio(contentMode: .fill) - .frame(width: 255, height: 150) - .clipShape(RoundedRectangle(cornerRadius: 5)) - - - Text(library.name ?? "Unknown") - .font(.subheadline) - } - } -} - -//#Preview { -// LibraryIconView(library: BaseItemDto()) -//} diff --git a/Jel/Views/Dashboard/Library/LibraryView.swift b/Jel/Views/Dashboard/Library/LibraryView.swift deleted file mode 100644 index 63bfd64..0000000 --- a/Jel/Views/Dashboard/Library/LibraryView.swift +++ /dev/null @@ -1,44 +0,0 @@ -// -// LibraryView.swift -// Jel -// -// Created by zerocool on 12/15/23. -// - -import SwiftUI -import JellyfinKit - -struct LibraryView: View { - @EnvironmentObject var jellyfinClient: JellyfinClientController - - @StateObject var authState: AuthStateController = AuthStateController.shared - - @State var libraries: [BaseItemDto] = [] - var body: some View { - ScrollView(.horizontal, showsIndicators: false) { - HStack { - ForEach(libraries) {library in - if library.collectionType == "movies" || library.collectionType == "tvshows" { - LibraryIconView(library: library) - } - } - } - } - .onAppear { - Task { - do { - let request = Paths.getUserViews(userID: authState.userId ?? "") - if let results = try await jellyfinClient.send(request).value.items { - libraries = results - } - } catch { - print(error) - } - } - } - } -} - -//#Preview { -// LibraryView() -//} -- cgit v1.2.3