-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #151 from 0x1-company/membership
feat: 🎸 membership
- Loading branch information
Showing
9 changed files
with
149 additions
and
136 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
122 changes: 122 additions & 0 deletions
122
Packages/BeMatch/Sources/MembershipFeature/Membership.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
import AnalyticsClient | ||
import ComposableArchitecture | ||
import SwiftUI | ||
|
||
@Reducer | ||
public struct MembershipLogic { | ||
public init() {} | ||
|
||
public struct State: Equatable { | ||
var child: Child.State? = .campaign(.init()) | ||
public init() {} | ||
} | ||
|
||
public enum Action { | ||
case onAppear | ||
case closeButtonTapped | ||
case child(Child.Action) | ||
} | ||
|
||
@Dependency(\.dismiss) var dismiss | ||
@Dependency(\.analytics) var analytics | ||
|
||
public var body: some Reducer<State, Action> { | ||
Reduce<State, Action> { _, action in | ||
switch action { | ||
case .onAppear: | ||
analytics.logScreen(screenName: "Membership", of: self) | ||
return .none | ||
|
||
case .closeButtonTapped: | ||
return .run { _ in | ||
await dismiss() | ||
} | ||
|
||
default: | ||
return .none | ||
} | ||
} | ||
.ifLet(\.child, action: \.child) { | ||
Child() | ||
} | ||
} | ||
|
||
@Reducer | ||
public struct Child { | ||
public enum State: Equatable { | ||
case campaign(MembershipCampaignLogic.State) | ||
case purchase(MembershipPurchaseLogic.State) | ||
} | ||
|
||
public enum Action { | ||
case campaign(MembershipCampaignLogic.Action) | ||
case purchase(MembershipPurchaseLogic.Action) | ||
} | ||
|
||
public var body: some Reducer<State, Action> { | ||
Scope(state: \.campaign, action: \.campaign) { | ||
MembershipCampaignLogic() | ||
} | ||
Scope(state: \.purchase, action: \.purchase) { | ||
MembershipPurchaseLogic() | ||
} | ||
} | ||
} | ||
} | ||
|
||
public struct MembershipView: View { | ||
let store: StoreOf<MembershipLogic> | ||
|
||
public init(store: StoreOf<MembershipLogic>) { | ||
self.store = store | ||
} | ||
|
||
public var body: some View { | ||
IfLetStore(store.scope(state: \.child, action: \.child)) { store in | ||
SwitchStore(store) { initialState in | ||
switch initialState { | ||
case .campaign: | ||
CaseLet( | ||
/MembershipLogic.Child.State.campaign, | ||
action: MembershipLogic.Child.Action.campaign, | ||
then: MembershipCampaignView.init(store:) | ||
) | ||
case .purchase: | ||
CaseLet( | ||
/MembershipLogic.Child.State.purchase, | ||
action: MembershipLogic.Child.Action.purchase, | ||
then: MembershipPurchaseView.init(store:) | ||
) | ||
} | ||
} | ||
} else: { | ||
ProgressView() | ||
.tint(Color.primary) | ||
} | ||
.ignoresSafeArea() | ||
.onAppear { store.send(.onAppear) } | ||
.toolbar { | ||
ToolbarItem(placement: .topBarLeading) { | ||
Button { | ||
store.send(.closeButtonTapped) | ||
} label: { | ||
Image(systemName: "xmark") | ||
.foregroundStyle(Color.primary) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
#Preview { | ||
NavigationStack { | ||
MembershipView( | ||
store: .init( | ||
initialState: MembershipLogic.State(), | ||
reducer: { MembershipLogic() } | ||
) | ||
) | ||
} | ||
.environment(\.colorScheme, .dark) | ||
.environment(\.locale, Locale(identifier: "ja-JP")) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file was deleted.
Oops, something went wrong.