From 3769b6354192c5ad1707600d7585e25ec3543110 Mon Sep 17 00:00:00 2001 From: Steve Streza Date: Thu, 31 Oct 2024 17:31:46 -0700 Subject: [PATCH] Move all PPOProjectCard methods into one enum and callback --- .../CardView/PPOProjectCard.swift | 35 +++++++++++++++---- .../PledgedProjectsOverview/PPOView.swift | 12 +++---- 2 files changed, 34 insertions(+), 13 deletions(-) diff --git a/Kickstarter-iOS/Features/PledgedProjectsOverview/CardView/PPOProjectCard.swift b/Kickstarter-iOS/Features/PledgedProjectsOverview/CardView/PPOProjectCard.swift index 07ca6e501c..f16f646aa7 100644 --- a/Kickstarter-iOS/Features/PledgedProjectsOverview/CardView/PPOProjectCard.swift +++ b/Kickstarter-iOS/Features/PledgedProjectsOverview/CardView/PPOProjectCard.swift @@ -4,12 +4,35 @@ import Library import SwiftUI struct PPOProjectCard: View { + enum Action { + case confirmAddress + case editAddress + case completeSurvey + case fixPayment + case authenticateCard + case viewBackingDetails + case sendMessage + + init(_ action: PPOProjectCardModel.Action) { + switch action { + case .confirmAddress: + self = .confirmAddress + case .editAddress: + self = .editAddress + case .completeSurvey: + self = .completeSurvey + case .fixPayment: + self = .fixPayment + case .authenticateCard: + self = .authenticateCard + } + } + } + @StateObject var viewModel: PPOProjectCardViewModel var parentSize: CGSize - var onViewBackingDetails: ((PPOProjectCardModel) -> Void)? = nil - var onSendMessage: ((PPOProjectCardModel) -> Void)? = nil - var onPerformAction: ((PPOProjectCardModel, PPOProjectCardModel.Action) -> Void)? = nil + var onAction: ((PPOProjectCardModel, Action) -> Void)? = nil var body: some View { VStack(spacing: Constants.spacing) { @@ -39,13 +62,13 @@ struct PPOProjectCard: View { // Handle actions .onReceive(self.viewModel.viewBackingDetailsTapped) { - self.onViewBackingDetails?(self.viewModel.card) + self.onAction?(self.viewModel.card, .viewBackingDetails) } .onReceive(self.viewModel.sendMessageTapped) { - self.onSendMessage?(self.viewModel.card) + self.onAction?(self.viewModel.card, .sendMessage) } .onReceive(self.viewModel.actionPerformed) { action in - self.onPerformAction?(self.viewModel.card, action) + self.onAction?(self.viewModel.card, .init(action)) } } diff --git a/Kickstarter-iOS/Features/PledgedProjectsOverview/PPOView.swift b/Kickstarter-iOS/Features/PledgedProjectsOverview/PPOView.swift index 53ee58174b..ca8d833079 100644 --- a/Kickstarter-iOS/Features/PledgedProjectsOverview/PPOView.swift +++ b/Kickstarter-iOS/Features/PledgedProjectsOverview/PPOView.swift @@ -46,14 +46,12 @@ struct PPOView: View { PPOProjectCard( viewModel: card, parentSize: parentSize, - onViewBackingDetails: { card in - self.viewModel.viewBackingDetails(from: card) - }, - onSendMessage: { card in - self.viewModel.contactCreator(from: card) - }, - onPerformAction: { card, action in + onAction: { card, action in switch action { + case .viewBackingDetails: + self.viewModel.viewBackingDetails(from: card) + case .sendMessage: + self.viewModel.contactCreator(from: card) case .authenticateCard: self.viewModel.fix3DSChallenge(from: card) case .completeSurvey: