From 628131e0083ffb76ee2f1c49a77cd31a438db913 Mon Sep 17 00:00:00 2001 From: Ethan Pippin Date: Thu, 4 Jul 2024 22:16:56 -0600 Subject: [PATCH] Fix Next Up Not Appearing on Home (#1142) --- .../HomeView/Components/NextUpView.swift | 26 +++++++++++++++---- Swiftfin/Views/HomeView/HomeView.swift | 5 +++- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/Swiftfin/Views/HomeView/Components/NextUpView.swift b/Swiftfin/Views/HomeView/Components/NextUpView.swift index a5c41415..98f3bd19 100644 --- a/Swiftfin/Views/HomeView/Components/NextUpView.swift +++ b/Swiftfin/Views/HomeView/Components/NextUpView.swift @@ -22,14 +22,16 @@ extension HomeView { private var router: HomeCoordinator.Router @ObservedObject - var homeViewModel: HomeViewModel + var viewModel: NextUpLibraryViewModel + + private var onSetPlayed: (BaseItemDto) -> Void var body: some View { - if homeViewModel.nextUpViewModel.elements.isNotEmpty { + if viewModel.elements.isNotEmpty { PosterHStack( title: L10n.nextUp, type: nextUpPosterType, - items: $homeViewModel.nextUpViewModel.elements + items: $viewModel.elements ) .content { item in if item.type == .episode { @@ -40,7 +42,7 @@ extension HomeView { } .contextMenu { item in Button { - homeViewModel.send(.setIsPlayed(true, item)) + onSetPlayed(item) } label: { Label(L10n.played, systemImage: "checkmark.circle") } @@ -51,10 +53,24 @@ extension HomeView { .trailing { SeeAllButton() .onSelect { - router.route(to: \.library, homeViewModel.nextUpViewModel) + router.route(to: \.library, viewModel) } } } } } } + +extension HomeView.NextUpView { + + init(viewModel: NextUpLibraryViewModel) { + self.init( + viewModel: viewModel, + onSetPlayed: { _ in } + ) + } + + func onSetPlayed(perform action: @escaping (BaseItemDto) -> Void) -> Self { + copy(modifying: \.onSetPlayed, with: action) + } +} diff --git a/Swiftfin/Views/HomeView/HomeView.swift b/Swiftfin/Views/HomeView/HomeView.swift index aa24518e..94a674a1 100644 --- a/Swiftfin/Views/HomeView/HomeView.swift +++ b/Swiftfin/Views/HomeView/HomeView.swift @@ -38,7 +38,10 @@ struct HomeView: View { ContinueWatchingView(viewModel: viewModel) - NextUpView(homeViewModel: viewModel) + NextUpView(viewModel: viewModel.nextUpViewModel) + .onSetPlayed { item in + viewModel.send(.setIsPlayed(true, item)) + } if showRecentlyAdded { RecentlyAddedView(viewModel: viewModel.recentlyAddedViewModel)