From f84d7965365dac912fe94881c97574d2ed6d7d4f Mon Sep 17 00:00:00 2001 From: Min-Yih Hsu Date: Thu, 27 Jan 2022 22:45:35 +0800 Subject: [PATCH] Simplify library display logics in LibraryListView And restore the filter that only shows supported library types. --- Swiftfin tvOS/Views/LibraryListView.swift | 34 ++++----------------- Swiftfin/Views/LibraryListView.swift | 37 ++++------------------- 2 files changed, 12 insertions(+), 59 deletions(-) diff --git a/Swiftfin tvOS/Views/LibraryListView.swift b/Swiftfin tvOS/Views/LibraryListView.swift index 480e20b6..9001544d 100644 --- a/Swiftfin tvOS/Views/LibraryListView.swift +++ b/Swiftfin tvOS/Views/LibraryListView.swift @@ -21,39 +21,17 @@ struct LibraryListView: View { @Default(.Experimental.liveTVAlphaEnabled) var liveTVAlphaEnabled + let supportedCollectionTypes = ["movies", "tvshows", "boxsets", "livetv", "other"] + var body: some View { ScrollView { LazyVStack { if !viewModel.isLoading { - if let collectionLibraryItem = viewModel.libraries.first(where: { $0.collectionType == "boxsets" }) { - Button { - self.libraryListRouter.route(to: \.library, - (viewModel: LibraryViewModel(parentID: collectionLibraryItem.id), - title: collectionLibraryItem.name ?? "")) - } - label: { - ZStack { - HStack { - Spacer() - VStack { - Text(collectionLibraryItem.name ?? "") - .foregroundColor(.white) - .font(.title2) - .fontWeight(.semibold) - } - Spacer() - }.padding(32) - } - .frame(minWidth: 100, maxWidth: .infinity) - .frame(height: 100) - } - .cornerRadius(10) - .shadow(radius: 5) - .padding(.bottom, 5) - } - - ForEach(viewModel.libraries.filter { $0.collectionType != "boxsets" }, id: \.id) { library in + ForEach(viewModel.libraries.filter { [self] library in + let collectionType = library.collectionType ?? "other" + return self.supportedCollectionTypes.contains(collectionType) + }, id: \.id) { library in if library.collectionType == "livetv" { if liveTVAlphaEnabled { Button { diff --git a/Swiftfin/Views/LibraryListView.swift b/Swiftfin/Views/LibraryListView.swift index 0ad8ee53..a7ebe468 100644 --- a/Swiftfin/Views/LibraryListView.swift +++ b/Swiftfin/Views/LibraryListView.swift @@ -16,6 +16,8 @@ struct LibraryListView: View { @StateObject var viewModel = LibraryListViewModel() + let supportedCollectionTypes = ["movies", "tvshows", "boxsets", "other"] + var body: some View { ScrollView { LazyVStack { @@ -42,37 +44,10 @@ struct LibraryListView: View { .padding(.bottom, 5) if !viewModel.isLoading { - - if let collectionsLibraryItem = viewModel.libraries.first(where: { $0.collectionType == "boxsets" }) { - Button { - libraryListRouter.route(to: \.library, - (viewModel: LibraryViewModel(parentID: collectionsLibraryItem.id), - title: collectionsLibraryItem.name ?? "")) - } label: { - ZStack { - ImageView(src: collectionsLibraryItem.getPrimaryImage(maxWidth: 500), - bh: collectionsLibraryItem.getPrimaryImageBlurHash()) - .opacity(0.4) - HStack { - Spacer() - VStack { - Text(collectionsLibraryItem.name ?? "") - .foregroundColor(.white) - .font(.title2) - .fontWeight(.semibold) - } - Spacer() - }.padding(32) - }.background(Color.black) - .frame(minWidth: 100, maxWidth: .infinity) - .frame(height: 100) - } - .cornerRadius(10) - .shadow(radius: 5) - .padding(.bottom, 5) - } - - ForEach(viewModel.libraries, id: \.id) { library in + ForEach(viewModel.libraries.filter { [self] library in + let collectionType = library.collectionType ?? "other" + return self.supportedCollectionTypes.contains(collectionType) + }, id: \.id) { library in Button { libraryListRouter.route(to: \.library, (viewModel: LibraryViewModel(parentID: library.id),