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 {
public enum ContactAction: Equatable {
case start
case dbContactFetched(XXModels.Contact?)
case saveFactsTapped
case sendRequestTapped
}
public struct ContactEnvironment {
......@@ -75,5 +77,11 @@ public let contactReducer = Reducer<ContactState, ContactAction, ContactEnvironm
case .dbContactFetched(let contact):
state.dbContact = contact
return .none
case .saveFactsTapped:
return .none
case .sendRequestTapped:
return .none
}
}
......@@ -24,110 +24,138 @@ public struct ContactView: View {
public var body: some View {
WithViewStore(store.scope(state: ViewState.init)) { viewStore in
Form {
Section {
if let dbContact = viewStore.dbContact {
if let xxContact = viewStore.xxContact {
Section {
Label(xxContact.username ?? "", systemImage: "person")
Label(xxContact.email ?? "", systemImage: "envelope")
Label(xxContact.phone ?? "", systemImage: "phone")
Button {
viewStore.send(.saveFactsTapped)
} label: {
if viewStore.dbContact == nil {
Text("Save contact")
} else {
Text("Update contact")
}
}
} header: {
Text("Facts")
}
}
if let dbContact = viewStore.dbContact {
Section {
Label(dbContact.username ?? "", systemImage: "person")
Label(dbContact.email ?? "", systemImage: "envelope")
Label(dbContact.phone ?? "", systemImage: "phone")
} else {
Text("Contact not saved locally")
} header: {
Text("Contact")
}
} header: {
Text("Local data")
}
Section {
Label(viewStore.xxContact?.username ?? "", systemImage: "person")
Label(viewStore.xxContact?.email ?? "", systemImage: "envelope")
Label(viewStore.xxContact?.phone ?? "", systemImage: "phone")
} header: {
Text("Facts")
}
Section {
switch viewStore.dbContact?.authStatus {
case .none, .stranger:
HStack {
Text("Stranger")
Spacer()
Image(systemName: "person.fill.questionmark")
}
case .requesting:
HStack {
Text("Sending auth request")
Spacer()
ProgressView()
}
case .requested:
HStack {
Text("Request sent")
Spacer()
Image(systemName: "paperplane")
}
case .requestFailed:
HStack {
Text("Sending request failed")
Spacer()
Image(systemName: "xmark.diamond.fill")
.foregroundColor(.red)
}
case .verificationInProgress:
HStack {
Text("Verification is progress")
Spacer()
ProgressView()
}
case .verified:
HStack {
Text("Verified")
Spacer()
Image(systemName: "person.fill.checkmark")
}
case .verificationFailed:
HStack {
Text("Verification failed")
Spacer()
Image(systemName: "xmark.diamond.fill")
.foregroundColor(.red)
}
case .confirming:
HStack {
Text("Confirming auth request")
Spacer()
ProgressView()
}
case .confirmationFailed:
HStack {
Text("Confirmation failed")
Spacer()
Image(systemName: "xmark.diamond.fill")
.foregroundColor(.red)
}
case .friend:
HStack {
Text("Friend")
Spacer()
Image(systemName: "person.fill.checkmark")
}
case .hidden:
HStack {
Text("Hidden")
Spacer()
Image(systemName: "eye.slash")
Section {
switch dbContact.authStatus {
case .stranger:
HStack {
Text("Stranger")
Spacer()
Image(systemName: "person.fill.questionmark")
}
Button {
viewStore.send(.sendRequestTapped)
} label: {
HStack {
Text("Send request")
Spacer()
Image(systemName: "chevron.forward")
}
}
case .requesting:
HStack {
Text("Sending auth request")
Spacer()
ProgressView()
}
case .requested:
HStack {
Text("Request sent")
Spacer()
Image(systemName: "chevron.forward")
}
case .requestFailed:
HStack {
Text("Sending request failed")
Spacer()
Image(systemName: "xmark.diamond.fill")
.foregroundColor(.red)
}
Button {
viewStore.send(.sendRequestTapped)
} label: {
HStack {
Text("Resend request")
Spacer()
Image(systemName: "paperplane")
}
}
case .verificationInProgress:
HStack {
Text("Verification is progress")
Spacer()
ProgressView()
}
case .verified:
HStack {
Text("Verified")
Spacer()
Image(systemName: "person.fill.checkmark")
}
case .verificationFailed:
HStack {
Text("Verification failed")
Spacer()
Image(systemName: "xmark.diamond.fill")
.foregroundColor(.red)
}
case .confirming:
HStack {
Text("Confirming auth request")
Spacer()
ProgressView()
}
case .confirmationFailed:
HStack {
Text("Confirmation failed")
Spacer()
Image(systemName: "xmark.diamond.fill")
.foregroundColor(.red)
}
case .friend:
HStack {
Text("Friend")
Spacer()
Image(systemName: "person.fill.checkmark")
}
case .hidden:
HStack {
Text("Hidden")
Spacer()
Image(systemName: "eye.slash")
}
}
} header: {
Text("Auth status")
}
} header: {
Text("Auth status")
.animation(.default, value: viewStore.dbContact?.authStatus)
}
}
.navigationTitle("Contact")
......
......@@ -44,4 +44,28 @@ final class ContactFeatureTests: XCTestCase {
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.
Finish editing this message first!
Please register or to comment