Skip to content

Commit

Permalink
Merge pull request #151 from 0x1-company/membership
Browse files Browse the repository at this point in the history
feat: 🎸 membership
  • Loading branch information
tomokisun authored Jan 13, 2024
2 parents ca4fedd + 01c2820 commit b7e1b6c
Show file tree
Hide file tree
Showing 9 changed files with 149 additions and 136 deletions.
16 changes: 8 additions & 8 deletions Packages/BeMatch/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ let package = Package(
.library(name: "MatchEmptyFeature", targets: ["MatchEmptyFeature"]),
.library(name: "MatchFeature", targets: ["MatchFeature"]),
.library(name: "MatchNavigationFeature", targets: ["MatchNavigationFeature"]),
.library(name: "MembershipFeature", targets: ["MembershipFeature"]),
.library(name: "NavigationFeature", targets: ["NavigationFeature"]),
.library(name: "NotificationsReEnableFeature", targets: ["NotificationsReEnableFeature"]),
.library(name: "OnboardFeature", targets: ["OnboardFeature"]),
.library(name: "PremiumFeature", targets: ["PremiumFeature"]),
.library(name: "ProfileExternalFeature", targets: ["ProfileExternalFeature"]),
.library(name: "ProfileFeature", targets: ["ProfileFeature"]),
.library(name: "ProfileSharedFeature", targets: ["ProfileSharedFeature"]),
Expand Down Expand Up @@ -183,6 +183,13 @@ let package = Package(
"MatchFeature",
"SettingsFeature",
]),
.target(name: "MembershipFeature", dependencies: [
"Styleguide",
"AnalyticsKeys",
.product(name: "ColorHex", package: "SDK"),
.product(name: "FeedbackGeneratorClient", package: "SDK"),
.product(name: "ComposableArchitecture", package: "swift-composable-architecture"),
]),
.target(name: "NavigationFeature", dependencies: [
"RecommendationFeature",
"MatchNavigationFeature",
Expand All @@ -204,13 +211,6 @@ let package = Package(
.product(name: "UserNotificationClient", package: "SDK"),
.product(name: "FirebaseStorageClient", package: "SDK"),
]),
.target(name: "PremiumFeature", dependencies: [
"Styleguide",
"AnalyticsKeys",
.product(name: "ColorHex", package: "SDK"),
.product(name: "FeedbackGeneratorClient", package: "SDK"),
.product(name: "ComposableArchitecture", package: "swift-composable-architecture"),
]),
.target(name: "ProfileExternalFeature", dependencies: [
"Constants",
"Styleguide",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@
}
}
},
"PremiumCampaign" : {
"MembershipCampaign" : {

},
"PremiumPurchase" : {
"MembershipPurchase" : {

},
"Recurring billing. You can cancel at any time. Payment will be charged to your iTunes account and your subscription will auto-renew at $500/week until you cancel in iTunes Store settings. By tapping Unlock, you agree to the Terms of Service and auto-renewal." : {
Expand Down
122 changes: 122 additions & 0 deletions Packages/BeMatch/Sources/MembershipFeature/Membership.swift
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"))
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import ComposableArchitecture
import SwiftUI

@Reducer
public struct PremiumCampaignLogic {
public struct MembershipCampaignLogic {
public init() {}

public struct State: Equatable {
Expand Down Expand Up @@ -39,10 +39,10 @@ public struct PremiumCampaignLogic {
}
}

public struct PremiumCampaignView: View {
let store: StoreOf<PremiumCampaignLogic>
public struct MembershipCampaignView: View {
let store: StoreOf<MembershipCampaignLogic>

public init(store: StoreOf<PremiumCampaignLogic>) {
public init(store: StoreOf<MembershipCampaignLogic>) {
self.store = store
}

Expand Down Expand Up @@ -74,10 +74,10 @@ public struct PremiumCampaignView: View {
}

#Preview {
PremiumCampaignView(
MembershipCampaignView(
store: .init(
initialState: PremiumCampaignLogic.State(),
reducer: { PremiumCampaignLogic() }
initialState: MembershipCampaignLogic.State(),
reducer: { MembershipCampaignLogic() }
)
)
.environment(\.colorScheme, .dark)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import ComposableArchitecture
import SwiftUI

@Reducer
public struct PremiumPurchaseLogic {
public struct MembershipPurchaseLogic {
public init() {}

public struct State: Equatable {
Expand All @@ -24,26 +24,26 @@ public struct PremiumPurchaseLogic {
return .none

case .onAppear:
analytics.logScreen(screenName: "PremiumPurchase", of: self)
analytics.logScreen(screenName: "MembershipPurchase", of: self)
return .none
}
}
}
}

public struct PremiumPurchaseView: View {
let store: StoreOf<PremiumPurchaseLogic>
public struct MembershipPurchaseView: View {
let store: StoreOf<MembershipPurchaseLogic>

public init(store: StoreOf<PremiumPurchaseLogic>) {
public init(store: StoreOf<MembershipPurchaseLogic>) {
self.store = store
}

public var body: some View {
WithViewStore(store, observe: { $0 }) { _ in
List {
Text("PremiumPurchase", bundle: .module)
Text("MembershipPurchase", bundle: .module)
}
.navigationTitle(String(localized: "PremiumPurchase", bundle: .module))
.navigationTitle(String(localized: "MembershipPurchase", bundle: .module))
.navigationBarTitleDisplayMode(.inline)
.task { await store.send(.onTask).finish() }
.onAppear { store.send(.onAppear) }
Expand All @@ -52,10 +52,10 @@ public struct PremiumPurchaseView: View {
}

#Preview {
PremiumPurchaseView(
MembershipPurchaseView(
store: .init(
initialState: PremiumPurchaseLogic.State(),
reducer: { PremiumPurchaseLogic() }
initialState: MembershipPurchaseLogic.State(),
reducer: { MembershipPurchaseLogic() }
)
)
}
109 changes: 0 additions & 109 deletions Packages/BeMatch/Sources/PremiumFeature/Premium.swift

This file was deleted.

0 comments on commit b7e1b6c

Please sign in to comment.