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

Update ContactFeature

parent aad544cd
No related branches found
No related tags found
2 merge requests!102Release 1.0.0,!68Messenger example - send auth request
This commit is part of merge request !68. Comments created here will be created in the context of that merge request.
...@@ -25,6 +25,8 @@ public struct ContactState: Equatable { ...@@ -25,6 +25,8 @@ public struct ContactState: Equatable {
public enum ContactAction: Equatable { public enum ContactAction: Equatable {
case start case start
case dbContactFetched(XXModels.Contact?) case dbContactFetched(XXModels.Contact?)
case saveFactsTapped
case sendRequestTapped
} }
public struct ContactEnvironment { public struct ContactEnvironment {
...@@ -75,5 +77,11 @@ public let contactReducer = Reducer<ContactState, ContactAction, ContactEnvironm ...@@ -75,5 +77,11 @@ public let contactReducer = Reducer<ContactState, ContactAction, ContactEnvironm
case .dbContactFetched(let contact): case .dbContactFetched(let contact):
state.dbContact = contact state.dbContact = contact
return .none return .none
case .saveFactsTapped:
return .none
case .sendRequestTapped:
return .none
} }
} }
...@@ -24,34 +24,51 @@ public struct ContactView: View { ...@@ -24,34 +24,51 @@ public struct ContactView: View {
public var body: some View { public var body: some View {
WithViewStore(store.scope(state: ViewState.init)) { viewStore in WithViewStore(store.scope(state: ViewState.init)) { viewStore in
Form { Form {
if let xxContact = viewStore.xxContact {
Section { Section {
if let dbContact = viewStore.dbContact { Label(xxContact.username ?? "", systemImage: "person")
Label(dbContact.username ?? "", systemImage: "person") Label(xxContact.email ?? "", systemImage: "envelope")
Label(dbContact.email ?? "", systemImage: "envelope") Label(xxContact.phone ?? "", systemImage: "phone")
Label(dbContact.phone ?? "", systemImage: "phone") Button {
viewStore.send(.saveFactsTapped)
} label: {
if viewStore.dbContact == nil {
Text("Save contact")
} else { } else {
Text("Contact not saved locally") Text("Update contact")
}
} }
} header: { } header: {
Text("Local data") Text("Facts")
}
} }
if let dbContact = viewStore.dbContact {
Section { Section {
Label(viewStore.xxContact?.username ?? "", systemImage: "person") Label(dbContact.username ?? "", systemImage: "person")
Label(viewStore.xxContact?.email ?? "", systemImage: "envelope") Label(dbContact.email ?? "", systemImage: "envelope")
Label(viewStore.xxContact?.phone ?? "", systemImage: "phone") Label(dbContact.phone ?? "", systemImage: "phone")
} header: { } header: {
Text("Facts") Text("Contact")
} }
Section { Section {
switch viewStore.dbContact?.authStatus { switch dbContact.authStatus {
case .none, .stranger: case .stranger:
HStack { HStack {
Text("Stranger") Text("Stranger")
Spacer() Spacer()
Image(systemName: "person.fill.questionmark") Image(systemName: "person.fill.questionmark")
} }
Button {
viewStore.send(.sendRequestTapped)
} label: {
HStack {
Text("Send request")
Spacer()
Image(systemName: "chevron.forward")
}
}
case .requesting: case .requesting:
HStack { HStack {
...@@ -64,7 +81,7 @@ public struct ContactView: View { ...@@ -64,7 +81,7 @@ public struct ContactView: View {
HStack { HStack {
Text("Request sent") Text("Request sent")
Spacer() Spacer()
Image(systemName: "paperplane") Image(systemName: "chevron.forward")
} }
case .requestFailed: case .requestFailed:
...@@ -74,6 +91,15 @@ public struct ContactView: View { ...@@ -74,6 +91,15 @@ public struct ContactView: View {
Image(systemName: "xmark.diamond.fill") Image(systemName: "xmark.diamond.fill")
.foregroundColor(.red) .foregroundColor(.red)
} }
Button {
viewStore.send(.sendRequestTapped)
} label: {
HStack {
Text("Resend request")
Spacer()
Image(systemName: "paperplane")
}
}
case .verificationInProgress: case .verificationInProgress:
HStack { HStack {
...@@ -129,6 +155,8 @@ public struct ContactView: View { ...@@ -129,6 +155,8 @@ public struct ContactView: View {
} header: { } header: {
Text("Auth status") Text("Auth status")
} }
.animation(.default, value: viewStore.dbContact?.authStatus)
}
} }
.navigationTitle("Contact") .navigationTitle("Contact")
} }
......
...@@ -44,4 +44,28 @@ final class ContactFeatureTests: XCTestCase { ...@@ -44,4 +44,28 @@ final class ContactFeatureTests: XCTestCase {
dbContactsPublisher.send(completion: .finished) dbContactsPublisher.send(completion: .finished)
} }
func testSaveFacts() {
let store = TestStore(
initialState: ContactState(
id: "contact-id".data(using: .utf8)!
),
reducer: contactReducer,
environment: .unimplemented
)
store.send(.saveFactsTapped)
}
func testSendRequest() {
let store = TestStore(
initialState: ContactState(
id: "contact-id".data(using: .utf8)!
),
reducer: contactReducer,
environment: .unimplemented
)
store.send(.sendRequestTapped)
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment