Skip to content
Snippets Groups Projects
Commit 5152e13d authored by Dariusz Rybicki's avatar Dariusz Rybicki
Browse files

Present CheckContactAuth from Contact

parent 33256ca4
No related branches found
No related tags found
2 merge requests!102Release 1.0.0,!81Messenger example - contact authorization improvements
......@@ -75,6 +75,7 @@ let package = Package(
name: "AppFeature",
dependencies: [
.target(name: "AppCore"),
.target(name: "CheckContactAuthFeature"),
.target(name: "ContactFeature"),
.target(name: "ContactsFeature"),
.target(name: "HomeFeature"),
......@@ -117,6 +118,7 @@ let package = Package(
name: "ContactFeature",
dependencies: [
.target(name: "AppCore"),
.target(name: "CheckContactAuthFeature"),
.target(name: "SendRequestFeature"),
.target(name: "VerifyContactFeature"),
.product(name: "ComposableArchitecture", package: "swift-composable-architecture"),
......
import AppCore
import CheckContactAuthFeature
import ContactFeature
import ContactsFeature
import Foundation
......@@ -49,6 +50,13 @@ extension AppEnvironment {
mainQueue: mainQueue,
bgQueue: bgQueue
)
},
checkAuth: {
CheckContactAuthEnvironment(
messenger: messenger,
mainQueue: mainQueue,
bgQueue: bgQueue
)
}
)
......
import AppCore
import CheckContactAuthFeature
import ComposableArchitecture
import ComposablePresentation
import Foundation
......@@ -18,7 +19,8 @@ public struct ContactState: Equatable {
importEmail: Bool = true,
importPhone: Bool = true,
sendRequest: SendRequestState? = nil,
verifyContact: VerifyContactState? = nil
verifyContact: VerifyContactState? = nil,
checkAuth: CheckContactAuthState? = nil
) {
self.id = id
self.dbContact = dbContact
......@@ -28,6 +30,7 @@ public struct ContactState: Equatable {
self.importPhone = importPhone
self.sendRequest = sendRequest
self.verifyContact = verifyContact
self.checkAuth = checkAuth
}
public var id: Data
......@@ -38,6 +41,7 @@ public struct ContactState: Equatable {
@BindableState public var importPhone: Bool
public var sendRequest: SendRequestState?
public var verifyContact: VerifyContactState?
public var checkAuth: CheckContactAuthState?
}
public enum ContactAction: Equatable, BindableAction {
......@@ -50,6 +54,9 @@ public enum ContactAction: Equatable, BindableAction {
case verifyContactTapped
case verifyContactDismissed
case verifyContact(VerifyContactAction)
case checkAuthTapped
case checkAuthDismissed
case checkAuth(CheckContactAuthAction)
case binding(BindingAction<ContactState>)
}
......@@ -60,7 +67,8 @@ public struct ContactEnvironment {
mainQueue: AnySchedulerOf<DispatchQueue>,
bgQueue: AnySchedulerOf<DispatchQueue>,
sendRequest: @escaping () -> SendRequestEnvironment,
verifyContact: @escaping () -> VerifyContactEnvironment
verifyContact: @escaping () -> VerifyContactEnvironment,
checkAuth: @escaping () -> CheckContactAuthEnvironment
) {
self.messenger = messenger
self.db = db
......@@ -68,6 +76,7 @@ public struct ContactEnvironment {
self.bgQueue = bgQueue
self.sendRequest = sendRequest
self.verifyContact = verifyContact
self.checkAuth = checkAuth
}
public var messenger: Messenger
......@@ -76,6 +85,7 @@ public struct ContactEnvironment {
public var bgQueue: AnySchedulerOf<DispatchQueue>
public var sendRequest: () -> SendRequestEnvironment
public var verifyContact: () -> VerifyContactEnvironment
public var checkAuth: () -> CheckContactAuthEnvironment
}
#if DEBUG
......@@ -86,7 +96,8 @@ extension ContactEnvironment {
mainQueue: .unimplemented,
bgQueue: .unimplemented,
sendRequest: { .unimplemented },
verifyContact: { .unimplemented }
verifyContact: { .unimplemented },
checkAuth: { .unimplemented }
)
}
#endif
......@@ -158,7 +169,19 @@ public let contactReducer = Reducer<ContactState, ContactAction, ContactEnvironm
state.verifyContact = nil
return .none
case .binding(_), .sendRequest(_), .verifyContact(_):
case .checkAuthTapped:
if let marshaled = state.dbContact?.marshaled {
state.checkAuth = CheckContactAuthState(
contact: .live(marshaled)
)
}
return .none
case .checkAuthDismissed:
state.checkAuth = nil
return .none
case .binding(_), .sendRequest(_), .verifyContact(_), .checkAuth(_):
return .none
}
}
......@@ -177,3 +200,10 @@ public let contactReducer = Reducer<ContactState, ContactAction, ContactEnvironm
action: /ContactAction.verifyContact,
environment: { $0.verifyContact() }
)
.presenting(
checkContactAuthReducer,
state: .keyPath(\.checkAuth),
id: .notNil(),
action: /ContactAction.checkAuth,
environment: { $0.checkAuth() }
)
import AppCore
import CheckContactAuthFeature
import ComposableArchitecture
import ComposablePresentation
import SendRequestFeature
......@@ -124,6 +125,15 @@ public struct ContactView: View {
Image(systemName: "chevron.forward")
}
}
Button {
viewStore.send(.checkAuthTapped)
} label: {
HStack {
Text("Check authorization")
Spacer()
Image(systemName: "chevron.forward")
}
}
} header: {
Text("Auth")
}
......@@ -149,6 +159,14 @@ public struct ContactView: View {
onDeactivate: { viewStore.send(.verifyContactDismissed) },
destination: VerifyContactView.init(store:)
))
.background(NavigationLinkWithStore(
store.scope(
state: \.checkAuth,
action: ContactAction.checkAuth
),
onDeactivate: { viewStore.send(.checkAuthDismissed) },
destination: CheckContactAuthView.init(store:)
))
}
}
}
......
import CheckContactAuthFeature
import Combine
import ComposableArchitecture
import CustomDump
......@@ -202,4 +203,42 @@ final class ContactFeatureTests: XCTestCase {
$0.verifyContact = nil
}
}
func testCheckAuthTapped() {
let contactData = "contact-data".data(using: .utf8)!
let store = TestStore(
initialState: ContactState(
id: Data(),
dbContact: XXModels.Contact(
id: Data(),
marshaled: contactData
)
),
reducer: contactReducer,
environment: .unimplemented
)
store.send(.checkAuthTapped) {
$0.checkAuth = CheckContactAuthState(
contact: .unimplemented(contactData)
)
}
}
func testCheckAuthDismissed() {
let store = TestStore(
initialState: ContactState(
id: "contact-id".data(using: .utf8)!,
checkAuth: CheckContactAuthState(
contact: .unimplemented("contact-data".data(using: .utf8)!)
)
),
reducer: contactReducer,
environment: .unimplemented
)
store.send(.checkAuthDismissed) {
$0.checkAuth = nil
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment