Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move all PPOProjectCard methods into one enum and callback #2190

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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))
}
}

Expand Down
12 changes: 5 additions & 7 deletions Kickstarter-iOS/Features/PledgedProjectsOverview/PPOView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down