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

Present MyContactView from SessionView

parent a047d57f
No related branches found
No related tags found
1 merge request!14[Example App] Make identity & contact
...@@ -66,6 +66,7 @@ let package = Package( ...@@ -66,6 +66,7 @@ let package = Package(
dependencies: [ dependencies: [
.target(name: "ErrorFeature"), .target(name: "ErrorFeature"),
.target(name: "LandingFeature"), .target(name: "LandingFeature"),
.target(name: "MyContactFeature"),
.target(name: "MyIdentityFeature"), .target(name: "MyIdentityFeature"),
.target(name: "SessionFeature"), .target(name: "SessionFeature"),
.product( .product(
...@@ -188,6 +189,7 @@ let package = Package( ...@@ -188,6 +189,7 @@ let package = Package(
name: "SessionFeature", name: "SessionFeature",
dependencies: [ dependencies: [
.target(name: "ErrorFeature"), .target(name: "ErrorFeature"),
.target(name: "MyContactFeature"),
.target(name: "MyIdentityFeature"), .target(name: "MyIdentityFeature"),
.product( .product(
name: "ComposableArchitecture", name: "ComposableArchitecture",
......
...@@ -3,6 +3,7 @@ import ComposableArchitecture ...@@ -3,6 +3,7 @@ import ComposableArchitecture
import ElixxirDAppsSDK import ElixxirDAppsSDK
import ErrorFeature import ErrorFeature
import LandingFeature import LandingFeature
import MyContactFeature
import MyIdentityFeature import MyIdentityFeature
import SessionFeature import SessionFeature
import SwiftUI import SwiftUI
...@@ -56,7 +57,8 @@ extension AppEnvironment { ...@@ -56,7 +57,8 @@ extension AppEnvironment {
bgScheduler: bgScheduler, bgScheduler: bgScheduler,
mainScheduler: mainScheduler, mainScheduler: mainScheduler,
error: ErrorEnvironment() error: ErrorEnvironment()
) ),
myContact: MyContactEnvironment()
) )
) )
} }
......
...@@ -2,6 +2,7 @@ import Combine ...@@ -2,6 +2,7 @@ import Combine
import ComposableArchitecture import ComposableArchitecture
import ElixxirDAppsSDK import ElixxirDAppsSDK
import ErrorFeature import ErrorFeature
import MyContactFeature
import MyIdentityFeature import MyIdentityFeature
public struct SessionState: Equatable { public struct SessionState: Equatable {
...@@ -10,13 +11,15 @@ public struct SessionState: Equatable { ...@@ -10,13 +11,15 @@ public struct SessionState: Equatable {
networkFollowerStatus: NetworkFollowerStatus? = nil, networkFollowerStatus: NetworkFollowerStatus? = nil,
isNetworkHealthy: Bool? = nil, isNetworkHealthy: Bool? = nil,
error: ErrorState? = nil, error: ErrorState? = nil,
myIdentity: MyIdentityState? = nil myIdentity: MyIdentityState? = nil,
myContact: MyContactState? = nil
) { ) {
self.id = id self.id = id
self.networkFollowerStatus = networkFollowerStatus self.networkFollowerStatus = networkFollowerStatus
self.isNetworkHealthy = isNetworkHealthy self.isNetworkHealthy = isNetworkHealthy
self.error = error self.error = error
self.myIdentity = myIdentity self.myIdentity = myIdentity
self.myContact = myContact
} }
public var id: UUID public var id: UUID
...@@ -24,6 +27,7 @@ public struct SessionState: Equatable { ...@@ -24,6 +27,7 @@ public struct SessionState: Equatable {
public var isNetworkHealthy: Bool? public var isNetworkHealthy: Bool?
public var error: ErrorState? public var error: ErrorState?
public var myIdentity: MyIdentityState? public var myIdentity: MyIdentityState?
public var myContact: MyContactState?
} }
public enum SessionAction: Equatable { public enum SessionAction: Equatable {
...@@ -37,8 +41,11 @@ public enum SessionAction: Equatable { ...@@ -37,8 +41,11 @@ public enum SessionAction: Equatable {
case didDismissError case didDismissError
case presentMyIdentity case presentMyIdentity
case didDismissMyIdentity case didDismissMyIdentity
case presentMyContact
case didDismissMyContact
case error(ErrorAction) case error(ErrorAction)
case myIdentity(MyIdentityAction) case myIdentity(MyIdentityAction)
case myContact(MyContactAction)
} }
public struct SessionEnvironment { public struct SessionEnvironment {
...@@ -48,7 +55,8 @@ public struct SessionEnvironment { ...@@ -48,7 +55,8 @@ public struct SessionEnvironment {
mainScheduler: AnySchedulerOf<DispatchQueue>, mainScheduler: AnySchedulerOf<DispatchQueue>,
makeId: @escaping () -> UUID, makeId: @escaping () -> UUID,
error: ErrorEnvironment, error: ErrorEnvironment,
myIdentity: MyIdentityEnvironment myIdentity: MyIdentityEnvironment,
myContact: MyContactEnvironment
) { ) {
self.getClient = getClient self.getClient = getClient
self.bgScheduler = bgScheduler self.bgScheduler = bgScheduler
...@@ -56,6 +64,7 @@ public struct SessionEnvironment { ...@@ -56,6 +64,7 @@ public struct SessionEnvironment {
self.makeId = makeId self.makeId = makeId
self.error = error self.error = error
self.myIdentity = myIdentity self.myIdentity = myIdentity
self.myContact = myContact
} }
public var getClient: () -> Client? public var getClient: () -> Client?
...@@ -64,6 +73,7 @@ public struct SessionEnvironment { ...@@ -64,6 +73,7 @@ public struct SessionEnvironment {
public var makeId: () -> UUID public var makeId: () -> UUID
public var error: ErrorEnvironment public var error: ErrorEnvironment
public var myIdentity: MyIdentityEnvironment public var myIdentity: MyIdentityEnvironment
public var myContact: MyContactEnvironment
} }
public let sessionReducer = Reducer<SessionState, SessionAction, SessionEnvironment> public let sessionReducer = Reducer<SessionState, SessionAction, SessionEnvironment>
...@@ -155,7 +165,17 @@ public let sessionReducer = Reducer<SessionState, SessionAction, SessionEnvironm ...@@ -155,7 +165,17 @@ public let sessionReducer = Reducer<SessionState, SessionAction, SessionEnvironm
state.myIdentity = nil state.myIdentity = nil
return .none return .none
case .error(_), .myIdentity(_): case .presentMyContact:
if state.myContact == nil {
state.myContact = MyContactState(id: env.makeId())
}
return .none
case .didDismissMyContact:
state.myContact = nil
return .none
case .error(_), .myIdentity(_), .myContact(_):
return .none return .none
} }
} }
...@@ -173,6 +193,13 @@ public let sessionReducer = Reducer<SessionState, SessionAction, SessionEnvironm ...@@ -173,6 +193,13 @@ public let sessionReducer = Reducer<SessionState, SessionAction, SessionEnvironm
action: /SessionAction.myIdentity, action: /SessionAction.myIdentity,
environment: \.myIdentity environment: \.myIdentity
) )
.presenting(
myContactReducer,
state: .keyPath(\.myContact),
id: .keyPath(\.?.id),
action: /SessionAction.myContact,
environment: \.myContact
)
#if DEBUG #if DEBUG
extension SessionEnvironment { extension SessionEnvironment {
...@@ -182,7 +209,8 @@ extension SessionEnvironment { ...@@ -182,7 +209,8 @@ extension SessionEnvironment {
mainScheduler: .failing, mainScheduler: .failing,
makeId: { fatalError() }, makeId: { fatalError() },
error: .failing, error: .failing,
myIdentity: .failing myIdentity: .failing,
myContact: .failing
) )
} }
#endif #endif
...@@ -2,6 +2,7 @@ import ComposableArchitecture ...@@ -2,6 +2,7 @@ import ComposableArchitecture
import ComposablePresentation import ComposablePresentation
import ElixxirDAppsSDK import ElixxirDAppsSDK
import ErrorFeature import ErrorFeature
import MyContactFeature
import MyIdentityFeature import MyIdentityFeature
import SwiftUI import SwiftUI
...@@ -61,6 +62,16 @@ public struct SessionView: View { ...@@ -61,6 +62,16 @@ public struct SessionView: View {
Image(systemName: "chevron.forward") Image(systemName: "chevron.forward")
} }
} }
Button {
viewStore.send(.presentMyContact)
} label: {
HStack {
Text("My contact")
Spacer()
Image(systemName: "chevron.forward")
}
}
} }
} }
.navigationTitle("Session") .navigationTitle("Session")
...@@ -89,6 +100,18 @@ public struct SessionView: View { ...@@ -89,6 +100,18 @@ public struct SessionView: View {
destination: MyIdentityView.init(store:) destination: MyIdentityView.init(store:)
) )
) )
.background(
NavigationLinkWithStore(
store.scope(
state: \.myContact,
action: SessionAction.myContact
),
onDeactivate: {
viewStore.send(.didDismissMyContact)
},
destination: MyContactView.init(store:)
)
)
} }
} }
} }
......
import ComposableArchitecture import ComposableArchitecture
import ElixxirDAppsSDK import ElixxirDAppsSDK
import ErrorFeature import ErrorFeature
import MyContactFeature
import MyIdentityFeature import MyIdentityFeature
import XCTest import XCTest
@testable import SessionFeature @testable import SessionFeature
...@@ -177,4 +178,25 @@ final class SessionFeatureTests: XCTestCase { ...@@ -177,4 +178,25 @@ final class SessionFeatureTests: XCTestCase {
$0.myIdentity = nil $0.myIdentity = nil
} }
} }
func testPresentingMyContact() {
let newId = UUID()
var env = SessionEnvironment.failing
env.makeId = { newId }
let store = TestStore(
initialState: SessionState(id: UUID()),
reducer: sessionReducer,
environment: env
)
store.send(.presentMyContact) {
$0.myContact = MyContactState(id: newId)
}
store.send(.didDismissMyContact) {
$0.myContact = 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